How to select only the records with the highest date in LINQ

前端 未结 5 1119
一向
一向 2020-11-28 03:15

I have a table, \'lasttraces\', with the following fields.

Id, AccountId, Version, DownloadNo, Date

The data looks like this:



        
5条回答
  •  执笔经年
    2020-11-28 03:59

    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

提交回复
热议问题