LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式

MMD*_*MNC 2 entity-framework c#-4.0

我正在使用以下代码:

using(var sd=new dataEntities())
{
var listofdata=sd.users.where(d=>d.id.ToString().Contain("2"));// id as int
// error : LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
}
Run Code Online (Sandbox Code Playgroud)

我看了看网站但没有找到答案

Noe*_*oel 7

您需要使用SQL函数来转换ToString方法.

SqlFunctions.StringConvert((double)id)
Run Code Online (Sandbox Code Playgroud)

回答: 在Linq中将int转换为实体的字符串的问题