Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

entity framework 4 - How to get the latest date inserted from the table with Linq to entities

how to retrieve the latestdate inspected from a column

In our app a user can inspect an item and when it inspected the current date is entered into the table. For the same item someother can uninspect it this time nothing is inserted into the table. Another user can inspect it and current date is inserted I need to get the LatestDate Inserted..how to get this with Linq

Let say table name is Statuses and col name is LastdateInspected

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sounds like you want something like:

var query = db.Statuses
              .OrderByDescending(x => x.LastDateInspected)
              .FirstOrDefault();

That will return null if there are no entries, or the value with the latest LastDateInspected value otherwise (i.e. the first result, having ordered by the last date inspected latest-first).

That will get you the whole record, of course. If you only want the date, you can select the LastDateInspected column.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...