asp.net mvc 3 - Complex SQL to LINQ in C# -


i'm newbie in linq , lamda expressions. have bit complex sql statement retrieves information several database tables:

select a.orderid, a.formjdeno, a.title, b.descr, c.code, c.descr, d.modificationdate orderform  left join orderpriority b on a.orderpriorityid = b.orderpriorityid  left join stockclass c on a.stockclassid = c.stockclassid  left join audittraillog d on a.orderid = d.objectid  d.columninfoid= 487 , d.oldvalue='1' , d.newvalue='2' , a.formstatus=2 , a.formtype=3 , b.orderpriorityid=1000001 , c.stockclassid=1000002 , a.deptid in      ( select deptid department instid = 1000006 ) , datediff(m,d.modificationdate, a.vendordeliverydate) >= 3    

i have linq done, using .contains() method replacing where...in sql clause, need make de joins restricting results basing on values belongs other tables , using datediff equivalent in linq. have got , working fine, no restricting results above sql statement. tried several ways no success. need equivalent linq

update:

finally able working. final linq retrieves same records sql statement. many @gert arnold:

var valid = dba.orderform             .where(q => q.formtype == 3                         && q.formstatus == 2                         && q.orderpriority.orderpriorityid == orderpriorityid                         && q.stockclass.stockclassid == stockclassid                         && dba.audittraillog.where(log => q.orderid==log.objectid)                                 .any(log => log.columninfoid == 487                                             &&  log.oldvalue == "1"                                             && log.newvalue == "2"                                             && entityfunctions.diffmonths(log.modificationdate,                                                                       q.vendordeliverydate) >= period)                         && departments.contains(q.deptid)); 

i think it:

dba.orderform.where(q => q.formtype == 3      && q.formstatus == 2        && q.orderpriority.orderpriorityid == 1000001     && q.stockclass.stockclassid == 1000002     && q.audittraillogs         .any(log => log.columninfoid == 487                  && log.oldvalue == "1"                  && log.newvalue == "2"                  && entityfunctions.diffmonths(log.modificationdate,                                                   q.vendordeliverydate) >= 3)     && departments.contains(q.deptid)); 

i assume you've got (or can create) navigation property ordertable.audittraillogs.

without navigation property can use

&& dba.audittraillogs.where(log => q.orderid == log.objectid).any(... 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -