Linq to Sql中的数据类型转换
我必须在linq查询连接语句中将数据类型从long转换为字符串。 例如
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是long类型,t2.field2是字符串类型。 当我把ToString方法抛出exception时。 exception消息
LINQ to Entities无法识别方法’System.String ToString()’方法,并且此方法无法转换为存储表达式。
任何帮助将不胜感激。
使用SqlFunctions.StringConvert
SqlFunctions.StringConvert((double) t1.field2)