我有以下方法,我计划返回一堆不同的日期时间对象。我所说的独特是指独特的日子(不包括时间)。
问题是,DateTime 对象具有不同的时间,因此即使它们是同一天,也会被评估为唯一。
如何让查询忽略日期的时间部分并仅评估日期的唯一性?
public List<DateTime> DistinctNoticeDates()
{
return (from notices in this.GetTable<Notice>()
orderby notices.Notice_DatePlanned descending
select notices.Notice_DatePlanned).Distinct().ToList();
}
Thanks.
尝试使用Date http://msdn.microsoft.com/library/system.datetime.date.aspx属性只获取日期DateTime
结构:
public List<DateTime> DistinctNoticeDates()
{
return (from notices in this.GetTable<Notice>()
orderby notices.Notice_DatePlanned descending
select notices.Notice_DatePlanned.Date)
.Distinct()
.ToList();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)