I have a device model:
public class DeviceModel
{
public DateTime Added { get;set; }
}
And i want to select devices count, grouped by Added
date (not Date and Time, but only date). My current implementation is not valid, because linq can't translate DateTime.Date
to sql:
var result = (
from device in DevicesRepository.GetAll()
group device by new { Date = device.Added.Date } into g
select new
{
Date = g.Key.Date,
Count = g.Count()
}
).OrderBy(nda => nda.Date);
How to change this query to make it work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…