[英]How to group linq expression only by date in datetime field
您好,我只需要按日期值運行以下查詢和分組datetime字段。
var startDateTime = regDate.Date;
var endDateTime = regDate.AddSeconds(fullDayinSeconds);
var res = from u in ObjectContext.Member.Where(o => o.RegisterTime >= startDateTime && o.RegisterTime <= endDateTime)
group u by new { u.PartnerId, u.RegisterTime.Date, u.partners.Name } into pgroup
let count = pgroup.Count()
select new PartnersUsersInfo
{
PartnerId = pgroup.Key.PartnerId.GetValueOrDefault(0),
PartnerName = pgroup.Key.Name, PartnerUsersAmount = count
};
u.RegisterTime.Date
返回異常LINQ to Entities不支持指定的類型成員'Date'。 我嘗試使用EntityFunctions.TruncateTime
但是對於組操作而言這是不可接受的。
怎么解決呢?
您可以嘗試添加帶有日期和分組的臨時列
采用
db.CallLogs.Where(r => DbFunctions.TruncateTime(r.DateTime)== callDateTime.Date).ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.