我的方法应该返回一个用户注释列表,所以我这样做了:
var saturday = DayOfWeek.Saturday;
var query = from note in userNotes
where note.NoteDate > lastMonth && note.NoteDate.DayOfWeek != saturday
select note;
但是我得到这个错误:
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties.
关于如何使用 linq 比较星期几的任何想法?
最佳答案
使用SqlFunctions.DatePart
静态方法。它将转化为DATEPART
TSQL 函数调用。
var saturday = (int)DayOfWeek.Saturday;
var query = from note in userNotes
where note.NoteDate > lastMonth && SqlFunctions.DatePart("dw", note.NoteDate) != saturday
select note;
关于c# - 如何在 LINQ to entities 中使用 Date 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18857972/