如何在Entity Framework和Mysql中使用规范函数 [英] how to use canonical functions in Entity Framework and Mysql
问题描述
我尝试使用 DbFunctions.AddMinutes(someminutes)
和 EntityFunctions.AddMinutes(someminutes)
但是当我执行我得到例如
FUNCTION projectName.AddMinutes不存在
我有谷歌搜索,但找不到如何执行规范功能。虽然有一个功能列表,但我又不知道他们属于哪个类
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查询如下
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});
在路上一些条件和分页被应用
其实我误解了错误它不是
FUNCTION projectName.AddMinutes不存在
但
FUNCTION databaseName。 AddMinutes不存在
我不知道是什么问题。我有不兼容的驱动程序/连接器,我不知道。
为了解决这个问题,我刚刚创建了名为AddMinutes的函数,它调用DATE_ADD()函数内部。函数定义如下
CREATE FUNCTION`AddMinutes`(actualDateTime datetime,minutesToAdd int)
RETURNS datetime
BEGIN
RETURN DATE_ADD(actualDateTime,INTERVAL minutesToAdd MINUTE);
END
我明白这不是正确的解决方案,而是一个HACK
I want to add Timespan to DateTime in EntityFramework with MySql Database.
i have tried using DbFunctions.AddMinutes(someminutes)
and EntityFunctions.AddMinutes(someminutes)
but when i execute i get exception something like
FUNCTION projectName.AddMinutes does not exist
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
I am using
- MySql.Data.Entities 6.8.3.0
- EntityFramework 6.0.0
- MySql.Data 6.8.4
- MySql.Web 6.8.4
- MySql (Database) 5.6.17
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 does not exist
but
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.
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
I understand that this is not proper solution, but a HACK
这篇关于如何在Entity Framework和Mysql中使用规范函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!