我有一个名为Billings的实体,具有DateTime属性。我需要唯一地找到日期,以便我可以通过他们做一些事情。 我想:与Linq不同的日期
var DistinctYearMonthsDays = (from t in db.Billings
where t.DateTime.HasValue
select t.DateTime.Value.Date).Distinct();
foreach (var day in DistinctYearMonthsDays)
,但我得到(在foreach
):
指定类型的成员 '日期' 不支持LINQ到实体。 仅支持初始值设定项,实体成员和实体导航属性 。
搜索后,我也尝试没有成功如下:
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));
任何帮助将是非常赞赏。
你看过[这] [1]页吗? [1]:http://stackoverflow.com/questions/5289338/linq-query-distinct-date – 2012-07-17 14:44:41