我有一組獨特的DateTime(沒有時間部分),用戶可以從用戶界面中進行選擇。這不僅是像「LastWeek」或「LastMonth」的範圍。用戶可以選擇他想要的每一天。 Linq在EntityFramework中查詢匹配結果的最佳方式是什麼?我有一個Foo屬性CreatedAt,它用時間部分存儲信息。當然,我不想檢查客戶端的CreatedAt屬性,SqlServer應該爲我做這項工作。實體框架:使用Linq查詢一組日期的最佳方法
我覺得應該是像成才:
var query = _entities.Foo.Where(x => x.UserID == user.ID);
if (selectedDates.IsNullOrEmpty() == false)
query = query.Where(x => x.CreatedAt 'IsIn' selectedDates);
or:
foreach (var date in selectedDates)
query = query.Where(x => x.CreatedAt.Year == date.Year && x.Month == date.Month && x.Day == date.Month) //but of course here I have the problem that I have to use the 'Or'-Operator, not 'And'.
我怎樣才能做到這一點?
'EntityFunctions.TruncateTime()'已過時,替換爲'DbFunctions.TruncateTime()' – mammadalius