gog*_*gog 5 c# linq linq-to-entities entity-framework
我的方法应该返回一个用户注释列表,所以我这样做:
var saturday = DayOfWeek.Saturday;
var query = from note in userNotes
where note.NoteDate > lastMonth && note.NoteDate.DayOfWeek != saturday
select note;
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
LINQ to Entities不支持指定的类型成员"Date".仅初始化程序,实体成员和实体导航属性.
有关如何使用linq比较星期几的任何想法?
Mar*_*zek 16
使用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;
Run Code Online (Sandbox Code Playgroud)