我需要编写一个 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/