2012-10-10 22 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

非常感謝諾埃爾。 –

相關問題