数据类型转换LINQ to SQL中 [英] data type casting in Linq to Sql

查看:154
本文介绍了数据类型转换LINQ to SQL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的数据类型由长转换为在LINQ查询字符串连接语句。
例如:

I have to convert data type from long to string in linq query join statement. e.g.

 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长型和t2.field2是字符串类型。
当我把ToString方法就抛出异常。
异常消息

t1.field2 is of long type and t2.field2 is of string type. When I put ToString method it throws exception. Exception message

LINQ到实体无法识别方法'System.String的ToString()方法,而这种方法不能被翻译成店的表情。

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

任何帮助将不胜感激。

推荐答案

使用的 SqlFunctions.StringConvert

SqlFunctions.StringConvert((double) t1.field2)

这篇关于数据类型转换LINQ to SQL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆