how to use canonical functions in Entity Framework and Mysql(如何在实体框架和 Mysql 中使用规范函数)
问题描述
我想使用 MySql 数据库在 EntityFramework 中将时间跨度添加到 DateTime.
I want to add Timespan to DateTime in EntityFramework with MySql Database.
我尝试过使用 DbFunctions.AddMinutes(someminutes)
和 EntityFunctions.AddMinutes(someminutes)
但是当我执行时我得到类似
i have tried using DbFunctions.AddMinutes(someminutes)
and EntityFunctions.AddMinutes(someminutes)
but when i execute i get exception something like
FUNCTION projectName.AddMinutes 不存在
FUNCTION projectName.AddMinutes does not exist
我已经用谷歌搜索但找不到如何执行规范函数.虽然有一个函数列表,但我还是不知道它们属于哪个类https://msdn.microsoft.com/en-us/library/bb738563.aspx
i have googled but cannot find how to execute canonical function. though there is a list of function but again i don't know which class they belong https://msdn.microsoft.com/en-us/library/bb738563.aspx
我正在使用
- MySql.Data.Entities 6.8.3.0
- EntityFramework 6.0.0
- MySql.Data 6.8.4
- MySql.Web 6.8.4
- MySql(数据库)5.6.17
我的 Linq 查询如下
My Linq Query is as below
IQueryable<OrderViewModel> orders = _dbContext.Orders
.OrderByDescending(x => x.ID)
.Select(x => new OrderViewModel
{ ID = x.ID,
AddedOn = DbFunctions.AddMinutes(x.AddedOn, diffMinutes).Value,
Customer = (x.IsGuestCheckOut == true ? x.CustomerEmail : x.Customer.FirstName + " " + x.Customer.LastName),
Phone = x.Phone,
TotalAmount = x.TotalAmount,
OrderStatus = x.OrderStatus });
在某些应用条件和分页的地方
down the road some where condition and pagination is applied
推荐答案
其实是我误会了错误不是
Actually i misunderstood the error it is not
FUNCTION projectName.AddMinutes 不存在
FUNCTION projectName.AddMinutes does not exist
但是
FUNCTION databaseName.AddMinutes 不存在
FUNCTION databaseName.AddMinutes does not exist
我不知道问题是什么.我有不兼容的驱动程序/连接器吗,我不知道.
I don't know what the issue is. Do i have any non-compatible driver/connector , I don't know.
为了解决这个问题,我刚刚创建了名为 AddMinutes 的函数,它在内部调用 DATE_ADD() 函数.函数定义如下
To solve this problem i just created function with name AddMinutes, it calls DATE_ADD() function internally. function definition is as below
CREATE FUNCTION `AddMinutes`(actualDateTime datetime, minutesToAdd int)
RETURNS datetime
BEGIN
RETURN DATE_ADD(actualDateTime, INTERVAL minutesToAdd MINUTE);
END
我知道这不是正确的解决方案,而是 HACK
I understand that this is not proper solution, but a HACK
这篇关于如何在实体框架和 Mysql 中使用规范函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在实体框架和 Mysql 中使用规范函数
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01