[英]How to get the last not logged-in user's within three weeks backwards?
我正在尝试获取过去三周内未登录的用户。 我听说过要使用的方法 Min 和 Max,但不确定如何使用。 所以我想获取过去三周未登录的用户,其中LoginDate
是用户日志列表:
var threeWeeksAgo = DateTime.Now.Date.AddDays(-21);
//userLogins is a table
var lastLogins = lowUsers.UserLogins
.Join(lowUsers.Clients, ul => ul.client, c => c.companyName, (ul, c) => new { ClientId = c.clientID, LoginDate = ul.dateTimeCreated, CompanyName = c.companyName })
.Where(a => a.LoginDate <= threeWeeksAgo);
如何使用过去三周未登录的用户列表检查 LoginDate。
数据:
Id UserName LoginDate
1 User1 01/10/2021 13:24
2 User2 02/09/2021 13:24
3 User1 03/10/2021 13:24
4 User1 04/10/2021 13:24
5 User2 03/09/2021 13:24
如果LoginDate
是DateTime
类型,您可以执行以下操作
var threeWeeksAgo = DateTime.Now.AddDays(-21);
//userLogins is a table
var notLoggedInUsers = userLogins.Where(a=>a.LoginDate < threeWeeksAgo).ToList();
您需要先按客户分组,为该组的日期排序,然后将上次登录日期与三周前进行比较。
var threeWeeksAgo = DateTime.Now.Date.AddDays(-21);
//userLogins is a table
var lastLogins = lowUsers.UserLogins
.Join(lowUsers.Clients, ul => ul.client, c => c.companyName, (ul, c) => new { ClientId = c.clientID, LoginDate = ul.dateTimeCreated, CompanyName = c.companyName })
.GroupBy(x => x.ClientId)
.Select(g => new { ClientId = g.Key, LastLoginDate = g.OrderByDescending(x => x.LoginDate).FirstOrDefault()?.LoginDate})
.Where(a => a.LastLoginDate <= threeWeeksAgo);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.