Reputation: 5069
I have This table "CommonData" in my mySql table
I want to query from c# using linq to find list of "Id" from latest inserted date. i.e. Here Latest Insert Date is "22-04-2013" , so I should get list of Ids whos insert date is "22-04-2013".
I am using Linq for it.
Some how I am not able to do this.
Upvotes: 1
Views: 617
Reputation: 7525
simple one might be using OrderByDescending
var result = CommonData.OrderByDescending(c=> c.InsertDate).Select(c => c.Id);
Upvotes: 0
Reputation: 17048
Add a subquery retrieving the maximum date, and then filter on this date:
var ids = ctx.CommonDatas
.Where(c => c.InsertDate ==
ctx.CommonDatas
.Max(c2 => c2.InsertDate)
)
.Select(c => c.Id);
Upvotes: 4