how to change sql query to linq? -


how change sql query linq? have 3 join last join select query.

select  mod.modserial,         met.metserial,         met.waterno,         met.powerno,         gro.groupdate      metldb.dbo.tblmet met      join metdb.dbo.tblmod mod on mod.modid= met.modid_fk        join metdb.dbo.tblgroupdata gro on gro.metid_fk= met.metid      join(select metid_fk,            max(groupdataid) maxgroupdata            metdb.dbo.tblgroupdata            group metid_fk) g on met.metid=g.metid_fk , gro.groupdataid=g.maxgroupdata 

here go pretty:

    using (metdbentities ctnx = new metdbentities())     {         var query1 = grp in ctnx.tblgroupdatas                      group grp grp.metid_fk g                      let maxid = g.max(gid => gid.groupdataid)                      select new { metid = g.key, maxid };          var query2 = met in ctnx.tblmets                      mod in ctnx.tblmods.where(mo => mo.modid == met.modid_fk)                      grp in ctnx.tblgroupdatas.where(gr => gr.metid_fk == met.metid)                      q1 in query1.where(q => q.metid == met.metid && grp.groupdataid == q.maxid)                      select new { mod.modserial, met.metserial, met.waterno, met.powerno, grp.groupdate };          var result = query2.tolist();     } 

edit: modified answer based on comment:

this methode cause problems larger dataset, because every record tblmets , tblmods , tblgroupdatas database memory...


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -