Pau*_*aul 4 c# linq-to-entities
此代码产生错误:
void GetLog()
{
List<CAR_STATUS_LOGS> logs = null;
using (TESTEntities ctx = new TESTEntities())
{
logs =
ctx.CAR_STATUS_LOGS
.Where(a => SqlFunctions.DatePart("DAY", a.TIMEMARK) == 1)
.ToList();
}
}
Run Code Online (Sandbox Code Playgroud)
错误是这样的:
LINQ to Entities无法识别方法'System.Nullable`1 [System.Int32] DatePart(System.String,System.Nullable`1 [System.DateTime])'方法,并且此方法无法转换为商店表达式.
我看不出我做错了什么SqlFunctions.DatePart.TIMEMARK列是Sqlserver DateTime类型.
有任何想法吗?
Ale*_*dre 15
您可以使用程序集EntityFramework.SqlServer.dll(Entity Framework 6.1.3)中的System.Data.Entity.SqlServer.SqlFunctions,例如:
myTable.Where (w =>
(System.Data.Entity.SqlServer.SqlFunctions.DatePart("weekday", w.Data).Value == 1);
Run Code Online (Sandbox Code Playgroud)