我想根據傳遞給我的函數的int來區分我的查詢。目前我有這個非常哈克解決方案:在運行時按日/周/月/年動態分組
`.GroupBy(occurrence => new { date =
// Bucket by day.
timeBucket == 0 ? DbFunctions.TruncateTime(occurrence.occurrenceDate) :
// Bucket by week.
timeBucket == 1 ? DbFunctions.AddDays(DbFunctions.CreateDateTime(occurrence.occurrenceDate.Year, 1, 1, 0, 0, 0), 7*(occurrence.occurrenceDate.DayOfYear/7)) :
// Bucket by month.
timeBucket == 2 ? DbFunctions.TruncateTime(DbFunctions.CreateDateTime(occurrence.occurrenceDate.Year, occurrence.occurrenceDate.Month, 1, 1, 1, 1)) :
// Bucket by year.
DbFunctions.TruncateTime(DbFunctions.CreateDateTime(occurrence.occurrenceDate.Year, 1, 1, 1, 1, 1)),
type = occurrence.type })`
的我是如何計算的日期的細節並不是我來說太重要(但隨時反正給予幫助)。我想避免爲數據庫中的每一行查看此case語句。無論如何避免這樣做?我已經嘗試了各種像使用表達式的解決方案,但我不能回到我想要的對象,因爲表達式樹必須參...
如果任何人有一個解決方案,將不勝感激。
謝謝!
這個工作!萬分感謝! –