Entity Framework converts int to string

entity-framework

Question

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?

1
29
10/2/2013 12:18:33 PM

Accepted Answer

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)
   }; 
50
2/18/2017 1:06:08 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow