Linq to Sql data casting

I need to convert a data type from long to string in linux query join statement. eg.

from t1 in table1 join t2 in table2 on new {t1.field1, t1.field2} equals new {t2.field1, t2.field2} select new {t1.field1,t2.field1 all columns} 

t1.field2 has a long type, and t2.field2 has a string type. When I put the ToString method, it throws an exception. Exception message

LINQ to Entities does not recognize the 'System.String ToString ()' method, and this method cannot be translated into a storage expression.

Any help would be appreciated.

+4
source share
1 answer

Use SqlFunctions.StringConvert

 SqlFunctions.StringConvert((double) t1.field2) 
+3
source

All Articles