EntityFramework 6.1.3和MySQL DbFunctions.TruncateTime不存在吗? [英] EntityFramework 6.1.3 and MySQL DbFunctions.TruncateTime does not exist?

查看:193
本文介绍了EntityFramework 6.1.3和MySQL DbFunctions.TruncateTime不存在吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用此查询来统计今天输入的内容.

Trying to get a count of things entered today using this query.

var today = DateTime.Today;
var unitsPassedToday = await this.db.Sessions
        .Where(x => DbFunctions.TruncateTime(x.FinishTime) == today)
        .CountAsync();

得到以下异常:

FUNCTION db.TruncateTime does not exist

我发誓我以前使用过此功能.我没有对System.Data.Entity的任何引用,这是我使用Google搜索找到的唯一解决方案.这是EntityFramework的MySQL实现中的某种错误吗?显然,我可以编写一个存储过程来返回此信息,但是我有点想知道为什么它不起作用?

I swear I've used this function before. I do not have any references to System.Data.Entity, which is the only solution I've found using a Google search. Is this some kind of bug with the MySQL implementation of EntityFramework? Obviously I could just write a stored procedure that returns this information, but I kinda wanna know why this isn't working?

MySQL服务器是5.5.23-企业.

MySQL server is 5.5.23-enterprise.

现在感觉有点笨,看来这应该是一个简单的问题,而我只是忽略了一些简单的事情...

Feeling kinda dumb right now, seems like this should be a simple problem and I'm just overlooking something simple...

这是SQL实体框架生成的...

Here is the SQL Entity Framework generates...

SELECT
`GroupBy1`.`A1` AS `C1`
FROM (SELECT
COUNT(1) AS `A1`
FROM `sessions` AS `Extent1`
WHERE (TruncateTime(`Extent1`.`finish_time`)) = @p__linq__0) AS `GroupBy1`

我很确定TruncateTime不是有效的MySQL函数,为什么要调用它呢?我想我还应该补充一点,我正在使用EDMX图表,而不是先编写代码.我已经在我的web.config中添加了codeConfigurationType,以便将MySQL定位为目标...

I'm pretty sure TruncateTime isn't a valid MySQL function, why would it be calling that? I guess I should also add I'm using EDMX diagrams and not code first. I have added the codeConfigurationType in my web.config to target MySQL though...

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">

MySql.Data.Entity是6.9.6.0版

MySql.Data.Entity is version 6.9.6.0

推荐答案

我在codeproject.com上找到了解决方案

I found a solution on codeproject.com

我已经测试了解决方案,为我工作!希望对您有帮助

I have tested the solution, worked for me! hope it helps

var data1 = context.my_model.Where(x => x.region_name == "Hong Kong" 
                        && x.price_date.Value.Year == dt.Year
                        && x.price_date.Value.Month == dt.Month
                        && x.price_date.Value.Day == dt.Day).ToList();

这篇关于EntityFramework 6.1.3和MySQL DbFunctions.TruncateTime不存在吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆