更新时间:2023-10-06 10:31:28
如果我没错,你想根据LoginTime
获得10个不同的用户。因此,您必须按UserId
对数据进行分组,并获得LoginTime
的最大值。
If i'm not wrong you want to get 10 distinct users based onLoginTime
. So, you have to group data byUserId
and get the max ofLoginTime
.
DateTime today12AM = new DateTime(2015,10,27,0,0,0);
DateTime today12PM = today12AM.AddDays(1);
var logLst=EJE.LoginDetails
.Where(m=>m.LoginTime>=today12AM && m.LoginTime<today12pm)>
.GroupBy(m=> m.UserId)
.Select(g=>new
{
UserId = g.Key(),
LoginTime = g.Max(t=>t.LoginTime)
})
.OrderByDescending(a=>a.LoginTime)
.Take(10)
.ToList();
试试!
Try!
var logLst = EJE.LoginDetails.Where(m=>m.UserID==userid).OrderByDescending(m=>m.LoginTime).Distinct().Take(10);
Enumerable.Distinct< tsource>方法(IEnumerable< tsource>) [ ^ ]
-KR
Enumerable.Distinct<tsource> Method (IEnumerable<tsource>)[^]
-KR