문제

I have a list of objects with Same ObjectId and I want to return the one with latest DateOrdered. Is this a good way to doing it?

var LatestObject = (from o in Context.Objects 
    where p.ObjectId == ObjectId 
    select p.DateOrdered)
    .ToList()
    .Max();
도움이 되었습니까?

해결책

No, it will only display latest date.Not your object, instead you can try:

Context.Objects.Where(p => p.ObjectId == ObjectId)
       .OrderByDescending(p => p.DateOrdered)
       .First();

다른 팁

You can try this:

var result = Context.Objects.Where(p => p.ObjectId == ObjectId).OrderByDescending(x => x.DateOrdered).FirstOrDefault();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top