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();
Question
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();
Solution
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();
OTHER TIPS
You can try this:
var result = Context.Objects.Where(p => p.ObjectId == ObjectId).OrderByDescending(x => x.DateOrdered).FirstOrDefault();