c# - LINQ with multiple left join and where clause -
i have following query, , converting linq.
select acq.acqpub prev_acqpub , ve.companyid , ve.entityid , ve.roundid , ve.entityname , ve.date , ve.roundtypecode , ve.eventtype , ve.postvalue_djvs , ve.postval , ve.preval , fin.financestat valuationevents_pit_new ve left join acq_publicdummy acq on ve.entityid = acq.entityid left join finstat_new fin on ve.entityid = fin.entityid ve.eventtype in('acq','lbo') , acq.acqpub null
i wanted double check if i've done right or there better way of doing it.
here code:
return (from ve in valuationevents ve.eventtype == eventtypes.acq || ve.eventtype == eventtypes.lbo join acq in acqpublicdummies on ve.entityid equals acq.entityid veacq x in veacq.defaultifempty() x != null && x.acqpub == null join fin in finstats on ve.entityid equals fin.entityid vefin y in vefin.defaultifempty() select new acqresearch { prevacqpub = x == null ? null : x.acqpub, entityid = ve.entityid, companyid = ve.companyid, roundid = ve.roundid, date = ve.date, roundtypecode = ve.roundtypecode, eventtype = ve.eventtype.tostring(), postvaluedjvs = ve.postmoneyvalue, postval = ve.postval, preval = ve.preval, financestat = y == null ? null : y.financestat }).tolist();
since result used > 1 times returning list instead of ienumerable.
also can't run sql , compare result of linq result, since query above runs against of raw data , linq running after data calculations , additional cleansing process. there no way me compare query result linq result. need rely logic correct. same sql logic , linq logic.
thank , feedback!
if want verify query same, can @ sql generated linq. there few ways of doing this:
- use sql profiler
- paste query linqpad , view sql tab
- set log property on datacontext
you can compare 2 sql queries , check differences.
as aside, in case things change style related - move of clauses above select clause, easier see filter applying. also, line
prevacqpub = x == null ? null : x.acqpub
seems may
prevacqpub = null
since have filtered out x null , have x.acqpub != null (same goes sql query).
Comments
Post a Comment