问题描述
我试图运行此查询:
DateTime DDate=DateTime.Today; //Today's date without Time
var v= db.measurements.Where(m => EntityFunctions.TruncateTime(m.InDate) == DDate);
这只是返回在那两个日期都是相等的对象,忽视了时间的一部分。
It just returns objects where those two dates are equal, ignoring the time part.
但我得到:
{FUNCTION [数据库] .TruncateTime不存在}
{"FUNCTION [database].TruncateTime does not exist"}
堆栈跟踪:
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数据库第一个
- .net框架4
- MySQL服务器5.6
- C# Visual Studio 2010
- EntityFramework 4 database first
- NetFramework 4
- MYSQL Server 5.6
MySQL.Data和MySQL.Data.Entity的版本是6.6.5.0。
The version of MySQL.Data and MySQL.Data.Entity is 6.6.5.0
推荐答案
我不解决这个问题,所以我刚刚创建了一个数据库名为TruncateTime功能。
I couldn't resolve it, so I just created a Function named "TruncateTime" in the database.
Create FUNCTION TruncateTime(dateValue DateTime) RETURNS date
return Date(dateValue);
和它的作品,但我不喜欢它。
And it works, but I don't like it.
这些人做过类似的事情:
These people did similar things:
的
CurrentUtcDateTime不存在 - 实体框架和MySQL
所以,现在我认为这可能是不必要的,我可以直接从数据库中调用它,仍然可以得到实体,是这样的:
So now I think that might be unnecessary and I can just call it directly from the database and still get entities, something like this:
var x = db.ExecuteStoreQuery<Measurement>(@"SELECT field1,field2
FROM Measurements
WHERE Date(InDate) = {0}", DDate);
而这一切。
And that's all.
这篇关于典型功能与QUOT; EntityFunctions.TruncateTime" MYSQL中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!