sql - ORA-00907: Distinct, join and group by in LINQ C# -
i'm getting error code ora-00907, when executing linq query below. seems oracle specific. problem seems "group by" subquery.
lets have these 2 tables: user , address, columns: user{userid, addressid}, address{addressid, streetname}
table address contains several rows same addressid, guess group address-table (distinct) on addressid 1 match addressid in user-table, should left join, if there no match still user-record.
i have tried several different approaches, code (example):
list<myobject> result = ( u in context.user.where(i => i.userid > 100) join in (from address in context.address group address address.addressid) on u.addressid equals a.firstordefault().addressid joinedaddress lfjoinedaddress in joinedaddress.defaultifempty() join email in context.email on u.userid equals email.userid jemail lfjemail in jemail.defaultifempty() select new myobject() { userid = u.userid, streetname = lfjoinedaddress.streetname, useremail = lfjemail.emailaddress } ).tolist();
someone know how achieve this, rewriting query works against oracle.
update:
this generated sql-query, except "email":
select 1 "c1", "extent1"."userid" "userid", "extent1"."addressid" "addressid" (select "user"."userid" "userid", "user"."addressid" "addressif", "ext"."user" "user") "extent1" left outer join (select "distinct1"."addressid" "addressid1", "limit1"."addressid" "addressid2", , "limit1"."streetname" "streetname1" (select distinct "extent2"."addressid" "addressid" (select "address"."addressid" "addressid", "address"."streetname" "streetname", "ext"."address" "address") "extent2" ) "distinct1" outer apply (select "extent3"."addressid" "addressid", "extent3"."streetname" "streetname" (select "address"."addressid" "addressid", "address"."streetname" "streetname", "ext"."address" "address") "extent3" ("distinct1"."addressid" = "extent3"."addressid") , (rownum <= (1) ) ) "limit1" outer apply (select "extent4"."addressid" "addressid", , "extent4"."streetname" "streetname" (select "address"."addressid" "addressid", "address"."streetname" "streetname", "ext"."address" "address") "extent4" ("distinct1"."addressid" = "extent4"."addressid") , (rownum <= (1) ) ) "limit2" ) "apply2" on ("extent1"."addressid" = "apply2"."addressid2") or (("extent1"."addressid" null) , ("apply2"."addressid3" null))))
distinct applied tuples not individual value within tuple. if streetname same per addressid in table address, want distinct tuples of (addressid, streetname). selecting distinct columns of context.address
subquery , omit .firstordefault()
.
join in ( address in context.address select new { address.addressid, address.streetname } ).distinct() on u.addressid equals a.addressid joinedaddress lfjoinedaddress in joinedaddress.defaultifempty()
if streetname not same per addressid, don't want distinct @ all.
Comments
Post a Comment