Hello I need to run the following query and group datetime field only by the date value.

 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 - returns the exception The specified type member 'Date' is not supported in LINQ to Entities. I have tried to use EntityFunctions.TruncateTime but it is not accepteble for group operations.

how to solve it ?

有帮助吗?

解决方案

you can try add temp col with date and group by it

其他提示

use
db.CallLogs.Where(r => DbFunctions.TruncateTime(r.DateTime) == callDateTime.Date).ToList();

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top