我想知道如何判断我的IEnumerable<T>
是否已作为内存列表加载(即已被评估)?
我希望此检查仅检查 DateTime 的日期部分以进行查询:
private IEnumerable<AccDocumentItem> FilterDocumentItemDateFilter(IEnumerable<AccDocumentItem> accDocumentItems, FilterDocumentDate filterDocumentDate)
{
accDocumentItems =
accDocumentItems.Where(x =>
x.AccDocument.CreateDate >= filterDocumentDate.FromDocumentDate &&
x.AccDocument.CreateDate <= filterDocumentDate.ToDocumentDate);
}
我知道LinqToEntity
我们可以使用EntityFunctions.TruncateTime
并且显然LinqToObject
我们可以获得日期部分,DateTime
但问题是我不知道我IEnumerable
是否已被执行?
编辑: 我想这样做:
private IEnumerable<AccDocumentItem> FilterDocumentItemDateFilter(IEnumerable<AccDocumentItem> accDocumentItems, FilterDocumentDate filterDocumentDate)
{
if(accDocumentItems as IList<AccDocumentItem> != null)
{
accDocumentItems =
accDocumentItems.Where(x =>
x.AccDocument.CreateDate.Date >= filterDocumentDate.FromDocumentDate &&
x.AccDocument.CreateDate.Date <= filterDocumentDate.ToDocumentDate);
}
else
{
accDocumentItems =
accDocumentItems.Where(x =>
EntityFunctions.TruncateTime(x.AccDocument.CreateDate) >= filterDocumentDate.FromDocumentDate &&
EntityFunctions.TruncateTime(x.AccDocument.CreateDate) <= filterDocumentDate.ToDocumentDate);
}
}
(谢谢蒂姆·施梅尔特;)