c# - How to limit a LINQ left outer join to one row -


I have a left external participant (below) returning expected results I get the 'first' hit from the 'right' table Need to be limited to I can do this? Currently, I get a result for each record in both tables, I want to see a result from the table on the left item (items), no matter how many results I have in the right table (photos).

  var from query = i dd.photos at i.id in db.items included in tempPhoto from tempPhoto in tempPhoto by tempPhoto.DefaultIffile () sorted by i.date descending new {itemName = i Select .name. , Item id = i.id, id = i.id, photoID = tp.PhotoID.ToString ()}; GridView1.DataSource = Query; GridView1.DataBind ();  

This will work for you.

  to i db.items let's do p = db.photos.Where (p2 = & gt; i.id == p2.item_id). First and default () order descending i.date new {itemName = i.name, itemID = i .id, id = i.id, photoID = p == faucet? Blank: p.photoID.ToString (); }  

When I created it against my own model (and without name and second id column in launch), then I found this SQL.

  SELECT [T0]. [ID] as [ID], Convert (Navarakar, (SELECT [t2]. [Photoid] (Top Top (1) [T1]. [Photo ID] FOR [DBO]. [Photo] AS [T 1] [Item 1]. [Item 1] [Item] AT [T]. [IT] [T.]. [IT] DESC  

When I asked for this plan , It showed that the subdivision has been applied by joining:

  RelOp LogicalOp = "left outer participant" physicalop = "nested loops" & gt;  

Comments