How to select only the records with the highest date in LINQ
If you just want the last date for each account, you'd use this:
var q = from n in table
group n by n.AccountId into g
select new {AccountId = g.Key, Date = g.Max(t=>t.Date)};
If you want the whole record:
var q = from n in table
group n by n.AccountId into g
select g.OrderByDescending(t=>t.Date).FirstOrDefault();
Here is a simple way to do it
var lastPlayerControlCommand = this.ObjectContext.PlayerControlCommands
.Where(c => c.PlayerID == player.ID)
.OrderByDescending(t=>t.CreationTime)
.FirstOrDefault();
Also have a look this great LINQ place - LINQ to SQL Samples
If you want the whole record,here is a lambda way:
var q = _context
.lasttraces
.GroupBy(s => s.AccountId)
.Select(s => s.OrderByDescending(x => x.Date).FirstOrDefault());