Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int to string in Entity Framework

How do you convert an int to a string in Link to EF?

The clr cant imagine casting an int to a string and Entity framework cant figure out what SQL snippet to translate .ToString() into.

So how do you write a linq statement that returns a string instead of an int?

like image 566
Rabbi Avatar asked Dec 21 '10 18:12

Rabbi


1 Answers

Sadly EF does not know how to convert .ToString(). You must use the embedded function SqlFunctions.StringConvert: http://msdn.microsoft.com/en-us/library/dd466292.aspx Also there is no overload for int so you must typecast to double :-(

var vendors =     from v in Vendors      select new    {                     Code = SqlFunctions.StringConvert((double)v.VendorId)    };  
like image 105
Karel Kral Avatar answered Sep 19 '22 16:09

Karel Kral