c# - Linq:如何在不同类型的键上连接表

标签 c# mysql linq entity-framework

我需要编写一个 LINQ 查询,以不同类型的键连接两个表表 t1 和 t2。 表t2的键(KeyB)为字符串,表t1的键(KeyA)为长。

我正在尝试以下操作,但出现异常:

Method 'System.String StringConvert(System.Nullable`1[System.Double])' has no supported translation to SQL

...
join t2 in table2 on SqlFunctions.StringConvert((double)t1.KeyA).Trim() equals t2.KeyB

正确的做法是什么?

最佳答案

使用 Convert.ToString(Your long value) 它将被转换为 SQL JOIN 子句。

Table1.Join(Table2, x => Convert.ToString(x.KeyA),  y =>  y.KeyB,
                    (x, y) => new { x,y })
                .ToList()

关于c# - Linq:如何在不同类型的键上连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28106669/

相关文章:

c# - 异步下载时设置用户状态

mysql错误;错误代码 : 1136. 列计数与第 1 行的值计数不匹配

mysql - Ruby 2 & Rails 4 查询在开发中返回结果,但在生产中返回 nil

php - mysql select 多表灵活输出

c# - StreamWriter 所有行到文件

c# - 在 UWP 中应用 TranslateTransform 时,外部渲染折线段不显示

c# - 为什么 C# 会针对 ushorts 上的模运算发出错误 "cannot implicitly convert int to ushort"?

c# - 如果图表数据为空,如何显示消息?

c# - 公共(public)属性 List 需要 Concat 2 types with inheritance

扩展/方法中的 C# Linq