我正在尝试运行此查询:
DateTime DDate=DateTime.Today; //Today's date without Time
var v= db.measurements.Where(m => EntityFunctions.TruncateTime(m.InDate) == DDate);
它只返回那两个日期相等的对象,忽略时间部分.
但我收到:
{“FUNCTION [数据库] .TruncateTime不存在”}
堆栈跟踪:
at MysqL.Data.MysqLClient.MysqLStream.ReadPacket()
at MysqL.Data.MysqLClient.NativeDriver.GetResult(Int32& affectedRow,Int64& insertedId)
at MysqL.Data.MysqLClient.Driver.GetResult(Int32 statementId,Int32& affectedRows,Int64& insertedId)
at MysqL.Data.MysqLClient.Driver.NextResult(Int32 statementId,Boolean force)
at MysqL.Data.MysqLClient.MysqLDataReader.NextResult()
at MysqL.Data.MysqLClient.MysqLCommand.ExecuteReader(CommandBehavior behavior)
at MysqL.Data.Entity.EFMysqLCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior)
我正在使用:
> C#Visual Studio 2010
> EntityFramework 4数据库优先
> NetFramework 4
> MysqL Server 5.6
最佳答案
我无法解决它,所以我只是在数据库中创建了一个名为“TruncateTime”的函数.
Create FUNCTION TruncateTime(dateValue DateTime) RETURNS date
return Date(dateValue);
它有效,但我不喜欢它.
这些人做了类似的事情:
Alternative to EntityFunctions.AddSeconds for MySQL
CurrentUtcDateTime does not exist – Entity Framework and MySql
所以现在我认为这可能是不必要的,我可以直接从数据库中调用它并仍然获取实体,如下所示:
var x = db.ExecuteStoreQuery
就这样.