2

I'm using the following code :

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

I looked at the site but did not find answer

MMD MNC
  • 149
  • 1
  • 5
  • 12
  • possible duplicate of [Problem with converting int to string in Linq to entities](http://stackoverflow.com/questions/1066760/problem-with-converting-int-to-string-in-linq-to-entities) – Ryan Kohn Dec 05 '14 at 17:18

1 Answers1

7

You need to use the SQL Function to translate the ToString method.

SqlFunctions.StringConvert((double)id)

Answered Here: Problem with converting int to string in Linq to entities

Community
  • 1
  • 1
Noel
  • 600
  • 16
  • 37
  • i'm use => var listofdata=sd.users.where(d=>SqlFunctions.StringConvert((double?)d.id).ToString().Contain("2"));// // error : LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression. – MMD MNC Oct 10 '12 at 16:36
  • Don't use the .ToString() method. The StringConvert does that for you. – Noel Oct 10 '12 at 16:38