开发者

how to create a linq query using join and max

开发者 https://www.devze.com 2023-01-02 20:38 出处:网络
I have 2 tables in my linq dbml.One is people with a uniqueid called peopleid and the other is a vertical with a foreign key for peopleid and a uniqueid called id.I need to create a type of linq query

I have 2 tables in my linq dbml. One is people with a uniqueid called peopleid and the other is a vertical with a foreign key for peopleid and a uniqueid called id. I need to create a type of linq query that does 开发者_运维问答a left outer join on people and gets the latest record in the vertical table based off the max(id) column. Can anyone suggest what this should look like? Thanks.


It should look like this (just a suggestion):

from p in con.Peoples
orderby p.LastName , p.FirstName
let maxPrint = p.FingerPrints
   .OrderByDescending(fp => fp.Id)
   .FirstOrDefault()
where maxPrint != null
select new {
  p.PeopleID,
  Name = p.FirstName + " " + p.LastName,
  FingerPrint = maxPrint
};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号