gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:32:43 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com