开发者

ASP.NET MVC linq-to-entities DateTime

开发者 https://www.devze.com 2023-02-06 07:47 出处:网络
I am having four fields in my LOGIN table , they are userid,username,password,datetime... In date time field, I set default value to Getdate() ... Now i want to retrive recently registered members to

I am having four fields in my LOGIN table , they are userid,username,password,datetime...

In date time field, I set default value to Getdate() ... Now i want to retrive recently registered members to last ...

I mean ,

ex..

uid    ...     datetime

1               1/21/2011 12:40:12 PM

2               1/23/2011 6:40:12 PM

3               1/24/2011 3:40:12 PM

4               1/24/2011 5:40:12 PM

I need to retrive values as ...

uid    ...     datetime

4               1/24/2011 5:40:12 PM

3               1/24/2011 3:40:12 PM

2        开发者_如何学JAVA       1/23/2011 6:40:12 PM

1               1/21/2011 12:40:12 PM

How to do this using LINQ query ??? Thank you


This will get you all the users that have logged in in the last 3 day:

(
  from l in Logins
  where
    l.datetime >= System.Data.Objects.SqlClient.SqlFunctions.DateAdd("day", -3, DateTime.Now)
  select l
).OrderByDescending(l => l.Data);

If you only want the last 10 users that have logged in, for instance, try this:

(
  from l in Logins
  select l
).OrderByDescending(l => l.Data).Take(10);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号