转换方法。 "对类型指定的方法不能被翻译成LINQ到实体店表述QUOT; [英] Convert Method. "The specified method on the type cannot be translated into a LINQ to Entities store expression"

查看:154
本文介绍了转换方法。 "对类型指定的方法不能被翻译成LINQ到实体店表述QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经迁移我的实体6.0从SQL Server到PostgreSQL项目。使用SQL Server,这几样我皈依查询用来工作properlly

I'd migrated my entity 6.0 project from SQL Server to PostGreSQL. With SQL Server, these kind of convertion on my queries used to work properlly

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:状态是一个布尔类型

PS: Status is a boolean type

DB_Function.cs

[System.Data.Entity.DbFunctionAttribute( "Business.Database", "ToInt32" )]
public static Int32 ToInt32( Boolean Val )
{
    return System.Convert.ToInt32( Val );
}



然而,当我迁移到PostgreSQL(并因此改变了我的EDMX),这些种转换不会再执行:

However, when I migrated to PostgreSQL (and therefore changed my EDMX), these kind of conversion don't execute anymore:

在键入
'DB_Function指定的方法的Int32 ToInt32(布尔)' +转换'不能转换成LINQ to实体
店的表情。

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),或者我失去了一些东西?

This error is related with PostGre (like int4 and not int32) or I'm missing something?

感谢。

推荐答案

有关了解什么类型的功能,我们可以在里面LINQ使用Enitities:经过下面的链接:
LINQ到实体无​​法识别方法

For understanding what type of functions we can use inside LINQ to Enitities : go through below linK : linq to entities doesn't recognize a method

现在在这种特殊情况下,我们是具有侧功能LINQ到entites的,这是无法转换为SQL查询,因此引发的异常。因此,通过删除它完美地工作的功能。

Now In this particular case we were having a function in side LINQ to Entites, which was unable to be translated to SQL Query and hence the Exception was thrown. SO by removing the function it work perfectly.

从M返回(
在objDB.Modules
排序依据m.ID
选择新
{
ID = m.ID,
名称= m.Name,
状态= m.Status ==真?1:0
}
);

return ( from m in objDB.Modules orderby m.ID select new { ID = m.ID, Name = m.Name, Status = m.Status == true ? 1 : 0 } );

这篇关于转换方法。 "对类型指定的方法不能被翻译成LINQ到实体店表述QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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