tags:

views:

42

answers:

1

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.

A: 

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
};
David B
I've not used let before and google doesn't seem to turn up a lot on linq to sql and let so I'm not sure exactly what the code should look like. Below is what I have now. Any idea what I'm doing wrong? Thanksvar recs = from p in con.Peoples join cj in con.Jobs on p.PeopleID equals cj.PeopleID join f in con.Fingerprints on p.PeopleID equals f.PeopleId let maxrec = (from fp in f select f.id).Max orderby p.LastName , p.FirstName select new { p.PeopleID, p.FirstName + " " + p.LastName };
geoff swartz
Great, thanks! I'll give that a try.
geoff swartz