user1727822
user1727822

Reputation: 121

how to write a linq to sql query for getting last record?

REcords are entering like this.

id     message    timestamp
1      hi         12-12-2012 11.00
2      gii        12-12-2012 11.01

How to write the query for getting new message record based on timestamp?i mean last record.

Upvotes: 0

Views: 147

Answers (1)

Carsten
Carsten

Reputation: 11646

Using the Max method.

DateTime[] arr = new DateTime[] 
    { DateTime.Today, DateTime.Today.AddDays(1), DateTime.Today.AddDays(2) };
DateTime lastEntity = arr.Max(x => x.Date);  // equals DateTime.Today.AddDays(2)

Upvotes: 1

Related Questions