linq to sql直接convert.todatetime就行了,ef用date.value不行,用System.Data.Objects.EntityFunctions.DiffDays和System.Data.Objects.SqlClient.SqlFunctions.DateDiff都直接报:
LINQ to Entities 不识别方法“System.Nullable`1[System.Int32] DiffDays(System.Nullable`1[System.DateTime], System.Nullable`1[System.DateTime])”,因此该方法无法转换为存储表达式。
LINQ to Entities 不识别方法“System.Nullable`1[System.Int32] DateDiff(System.String, System.Nullable`1[System.DateTime], System.Nullable`1[System.DateTime])”,因此该方法无法转换为存储表达式。
请问该用什么方法?以下是linq语句:
var str = from p in db.UnsalableSalesRptReasons
where !p.UnsalableRpt.IsFiling
&& p.CeateTime != null
//&& System.Data.Objects.EntityFunctions.DiffDays(p.CeateTime, DateTime.Now) > 30
&& System.Data.Objects.SqlClient.SqlFunctions.DateDiff("D", p.CeateTime, DateTime.Now) > 1
select p.UnsalableRpt.ItemId;
其中p.CeateTime是datetime?类型
...全文
64111打赏收藏
请问EF中对可为null的日期字段进行判断时如何转换?
linq to sql直接convert.todatetime就行了,ef用date.value不行,用System.Data.Objects.EntityFunctions.DiffDays和System.Data.Objects.SqlClient.SqlFunctions.DateDiff都直接报: LINQ to Entities 不识别方法“System.Nullable`1[System.Int32] DiffDays(System.Nullable`1[System.DateTim
However, Entity Framework 6 has removed the dependency on System.Data.Entity and has redefined all necessary classes for that purpose inside of the EntityFramework assembly.
Meaning that, in the case of your console app, I am guessing that either by design (System.Data.Entity is not referenced) or by accident (System.Data.Entity is referenced but the EntityFunctions class is taken from EntityFramework.dll), the correct version of EntityFunctions (from EntityFramework.dll) is taken.
If you are using any version of Entity Framework 6, make sure that you are using the EntityFunctions class that can be found in EntityFramework.dll, not the one in System.Data.Entity. Source code of EntityFunctions.cs in Entity Framework 6
Actually, if you use Entity Framework 6, I would recommend removing all and any references to System.Data.Entity - in order to avoid any future confusion and mistake.
However, Entity Framework 6 has removed the dependency on System.Data.Entity and has redefined all necessary classes for that purpose inside of the EntityFramework assembly.
Meaning that, in the case of your console app, I am guessing that either by design (System.Data.Entity is not referenced) or by accident (System.Data.Entity is referenced but the EntityFunctions class is taken from EntityFramework.dll), the correct version of EntityFunctions (from EntityFramework.dll) is taken.
If you are using any version of Entity Framework 6, make sure that you are using the EntityFunctions class that can be found in EntityFramework.dll, not the one in System.Data.Entity. Source code of EntityFunctions.cs in Entity Framework 6
Actually, if you use Entity Framework 6, I would recommend removing all and any references to System.Data.Entity - in order to avoid any future confusion and mistake.
However, Entity Framework 6 has removed the dependency on System.Data.Entity and has redefined all necessary classes for that purpose inside of the EntityFramework assembly.
Meaning that, in the case of your console app, I am guessing that either by design (System.Data.Entity is not referenced) or by accident (System.Data.Entity is referenced but the EntityFunctions class is taken from EntityFramework.dll), the correct version of EntityFunctions (from EntityFramework.dll) is taken.
If you are using any version of Entity Framework 6, make sure that you are using the EntityFunctions class that can be found in EntityFramework.dll, not the one in System.Data.Entity. Source code of EntityFunctions.cs in Entity Framework 6
Actually, if you use Entity Framework 6, I would recommend removing all and any references to System.Data.Entity - in order to avoid any future confusion and mistake.