c# - Linq to Sql 中的数据类型转换

标签 c# linq

我必须在 linq 查询连接语句中将数据类型从 long 转换为 string。 例如

 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是string类型。 当我放置 ToString 方法时,它会抛出异常。 异常信息

LINQ to Entities 无法识别“System.String ToString()”方法,并且无法将此方法转换为存储表达式。

我们将不胜感激。

最佳答案

使用SqlFunctions.StringConvert

SqlFunctions.StringConvert((double) t1.field2)

关于c# - Linq to Sql 中的数据类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14252717/

相关文章:

C# 在 50% 不透明窗体上绘制的透明实心矩形

.net - .net 4.0表达式树的好用例是什么?

c# - 在 Linq 中不符合条件

c# - 如何在 sitecore 中创建自定义 token

c# - 如何将 Webbrowser 对象转换为 AxWebbrowser?

c# - 应用关闭 Xamarin Forms 后丢失数据/文件

c# - 使用 linq 生成动态集合

c# - 带有 nhibernate/fluent 的枚举标志

c# - LINQ 按名称选择属性

c# - 在 LINQ 中表达组查询时遇到问题