- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已将实体 6.0 项目从 SQL Server 迁移到 PostGreSQL。使用 SQL Server,这些对我的查询的转换过去可以正常工作
Module.cs
return (
from m in objDB.Modules
orderby m.ID
select new
{
ID = m.ID,
Name = m.Name,
Status = DB_Function.Convert.ToInt32( m.Status )
}
);
PS: Status是boolean类型
DB_Function.cs
[System.Data.Entity.DbFunctionAttribute( "Business.Database", "ToInt32" )]
public static Int32 ToInt32( Boolean Val )
{
return System.Convert.ToInt32( Val );
}
但是,当我迁移到 PostgreSQL(并因此更改了我的 EDMX)时,这些类型的转换不再执行:
The specified method 'Int32 ToInt32(Boolean)' on the type 'DB_Function+Convert' cannot be translated into a LINQ to Entities store expression.
这个错误与 PostGre 有关(比如 int4 而不是 int32)或者我遗漏了什么?
提前致谢。
最佳答案
要了解我们可以在 LINQ to Enitities 中使用什么类型的函数:请浏览以下链接: linq to entities doesn't recognize a method
现在在这种特殊情况下,我们在 LINQ to Entites 中有一个函数,它无法转换为 SQL 查询,因此抛出了异常。因此,通过删除该功能,它可以完美地工作。
返回( 来自 objDB.Modules 中的 m orderby m.ID 选择新的 { ID = m.ID, 姓名 = m.姓名, 状态 = m.Status == 真? 1 : 0 } );
关于c# - 转换方法。 "The specified method on the type cannot be translated into a LINQ to Entities store expression",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30782788/
我是一名优秀的程序员,十分优秀!