linq - How do I use subquery, groupby, max, and top in single linqToSql statement? -


To use LinqToSql I need to return one (L) to the most recent modDate in a host table (CL).

Tables: L (lid, meta1, meta2, ...)
cl (cid, lid , Modidate)

Here is the SQL which produces the expected result

  Select L * Join ELL Inner (Select Top 1 CL, Lid, Max (CL Moded) from CDL CL Inner as LL.D. on LL.L.O.LL ON CLL LLL = LID and L.meta1 = 5 Group by CL.MAD (CL). Moddet) L. Lid = M.Lid  

on L as a lid order by DISC Sufficient simple subkey introduces us in IDs Query those records with matching IDE

  var subquery = db.L. where (L = & gt; L. Mata1 = 5) Select multiple (L => LCLS). GroupB (CL) = & Gt; CL.Lid). Order by Descending (G => G.MX (CL => CL.Modet)). Select (G = & gt; G). (1) var Query = db ltd .. where (l => subquery.Any (id => l.lid == id))  

Looking forward to this, you will get the subquery Can be removed from:

  var query = db.L. where (L = & gt; L. Mata1 = 5). Selection Mono (L => LCLS) .GroupBy (CL = & gt; CL.Lid) .OderByDescending = = Gmx (cl = & gt; CL.moddate)). Select (g = & gt; g.first (.l);  

Comments