2012-10-10 21 views
2

我使用以下代码:LINQ到实体无法识别方法“System.String的ToString()”方法,和这种方法不能被翻译成表达商店

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. 
} 

我看着网站,但没有找到答案

+0

可能重复http://stackoverflow.com/questions/1066760/problem-with-converting-int -to-字符串在-LINQ到实体) –

回答

7

你需要使用SQL函数翻译的ToString方法。

SqlFunctions.StringConvert((double)id) 

回答这里: Problem with converting int to string in Linq to entities

[问题与LINQ的转换的int字符串实体(的
+0

即时使用=>无功listofdata = sd.users.where(d => SqlFunctions.StringConvert((双?)d.id)的ToString()。含(“2”)); // //错误:LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式。 –

+0

不要使用.ToString()方法。 StringConvert为你做。 – Noel

+0

非常感谢诺埃尔。 –

相关问题