var events = context.Events………
Events has a property ‘DueDate’ (Datetime)
I want to select most recent 5 records, how to write such a query? Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are interested in the Events that are closest to day you could do this:
This takes the events that are the least number of days away from today (in the past OR future).
If you wanted events that are most recent but only in the future, you could do:
Edit:
If you use LINQ to Entities
DateTimemanipulation is not directly supported, but if you use SQL server something like DateDiff should work (untested you’ll have to try out yourself):If that doesn’t work you can always get your data first, then filter with LINQ to objects, which has the added benefits that you’re not tying yourself to SQL Server – but obviously it’s not very efficient: