gpt4 book ai didi

.net - 两个表在 lambda 表达式中具有多个连接条件

转载 作者:行者123 更新时间:2023-12-03 09:25:02 25 4
gpt4 key购买 nike

我想加入两个表。两个表的连接列均为column3、column4。

Visual Studio 抛出以下错误:

The type arguments for method

'System.Linq.Enumerable.Join (System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Func, System.Func, System.Func)'

cannot be inferred from the usage. Try specifying the type arguments explicitly.

我的代码如下:

int i = context.Table1.Where(u => u.column1 == true).Join(
context.Table2.Where(u => u.column2.ToUpper() == "COMPLETED"),
q => new { Column3 = q.column3, Column4 = q.column4 },
u => new { Column3 = u.column3, Column4 = u.column4 },
(q, u) => new { q.column1 }).Count();

这个查询有什么问题?

提前致谢。

最佳答案

查询本身看起来不错,但我们不知道 context.TableX 的完整类型。 .

对于要编译的 Join,由 new { Column3 = q.column3, Column4 = q.column4 } 定义的两种匿名类型各部分需要具有相同的属性类型,以便生成的匿名类型相同。执行 Table1 的条目和Table2具有相同的类型,或者它们的列类型可能不匹配?

在我的机器上,该行

l1.Join(l2, 
d => new { P = d.Column1, Q = d.Column2 },
d => new { P = d.Column1, Q = d.Column2 },
(d, u) => new { d.Column1 }).Count();

编译良好,带有 l1l2两者都是 List<Dummy> 类型和Dummy只有两个整数属性。

关于.net - 两个表在 lambda 表达式中具有多个连接条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22984596/

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