当前位置: 首页 > 编程语言 > C#

MYSQL中不存在规范函数“EntityFunctions.TruncateTime”Share

时间:2023-04-11 02:07:00 C#

MYSQL中不存在规范函数“EntityFunctions.TruncateTime”//没有时间的今天日期varv=db.measurements.Where(m=>EntityFunctions.TruncateTime(m.InDate)==DDate);它只返回这两个日期相等的对象,忽略时间部分。但我得到:{"FUNCTION[Database].TruncateTimedoesnotexist"}堆栈跟踪:在MySql.Data.MySqlClient.MySqlStream.ReadPacket()在MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&affectedRow,Int64&insertedId)在MySql.Data.MySqlClient.Driver.GetResult(Int32statementId,Int32&affectedRows,Int64&insertedId)在MySql.Data.MySqlClient.Driver.NextResult(Int32statementId,Booleanforce)在MySql.Data.MySqlClient.MySqlDataS(Reader).NextResult。Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior行为)在MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior行为)在System.Data.Common.DbCommand.ExecuteReader(CommandBehavior行为)在System.Data.ExandsDeecutionCommandClient.Eition(EntityCommand实体),CommandBehaviorbehavior)我使用的是:MySQL.Data和MySQL.Data.Entity版本是6.6.5.0MySQL支持TruncateTime。同样的事情也发生在这个人身上。我无法解决,所以我只是在数据库中创建了一个名为“TruncateTime”的函数。创建FUNCTIONTruncateTime(dateValueDateTime)RETURNSdatereturnDate(dateValue);它有效,但我不喜欢它。这些人做了类似的事情:MySQL的EntityFunctions.AddSeconds替换CurrentUtcDateTime不存在-实体框架和MySql所以现在我认为这可能是不必要的,我可以直接从数据库调用它并仍然得到如下所示的实体:varx=db.ExecuteStoreQuery(@"SELECTfield1,field2FROMMeasurementsWHEREDate(InDate)={0}",DDate);就是这样。Torres的响应方法有效,但对我来说感觉很笨拙,所以我找到了另一种方法(这适用于EF6,对于EF5,存在类似的方法,但我无法测试它):创建类DatabaseFunctions并添加到其中添加以下代码:[Function(FunctionType.BuiltInFunction,"Date")]publicstaticDateTime?日期(DateTime?dateValue)=>Function.CallNotSupported();将以下行添加到OnModelCreatingprotectedoverridevoidOnModelCreating(DbModelBuildermodelBuilder){modelBuilder.Conventions.Add(newFunctionConvention())//...}使用DatabaseFunctions.Date而不是EntityFunctions.TruncateTime。以上为C#学习教程:暂无标准函数《EntityFunctions》。如涉及侵权,请点击右边联系管理员删除。如需转载,请注明出处: