我有一个名为 Billings 的实体,其属性为 DateTime。我需要唯一地找到日期,以便我可以浏览它们并做一些事情。我试过:
var DistinctYearMonthsDays = (from t in db.Billings
where t.DateTime.HasValue
select t.DateTime.Value.Date).Distinct();
foreach (var day in DistinctYearMonthsDays)
但我得到(在foreach
):
LINQ to Entities 不支持指定的类型成员“日期”。仅支持初始化程序、实体成员和实体导航属性。
搜索后,我还尝试了以下操作,但均未成功:
IEnumerable<DateTime> DistinctYearMonthsDays = db.Billings
.Select(p => new
{
p.DateTime.Value.Date.Year,
p.DateTime.Value.Date.Month,
p.DateTime.Value.Date.Day
}).Distinct()
.ToList()
.Select(x => new DateTime(x.Year,x.Month,x.Day));
任何帮助将不胜感激。