gpt4 book ai didi

c# - 多个 linq 连接但不同的运算符

转载 作者:太空宇宙 更新时间:2023-11-03 18:37:47 25 4
gpt4 key购买 nike

我将如何在 LINQ 中表达以下内容?

select * from table_1 t1
join table_2 t2 on t1.col1 = t2.col1 and t1.col2 <= t2.col2

这是我尝试过的方法,但我没有得到想要的结果。我正在尝试加入2 个表,但由于 table_1 的数量不大于或等于 table_2WidgetA 的数量我不希望结果中有任何记录(在 xList 中)。

    List<anObj> table_1 = new List<anObj>();
table_1.Add(new anObj() { Product = "WidgetA", Quantity = 0 });
table_1.Add(new anObj() { Product = "WidgetB", Quantity = 3 });

List<anObj> table_2 = new List<anObj>();
table_2.Add(new anObj() { Product = "WidgetA", Quantity = 1 });
table_2.Add(new anObj() { Product = "WidgetB", Quantity = 1 });

var xList =
from t1 in table_1
join t2 in table_2
on t1.Product equals t2.Product
where t1.Quantity >= t2.Quantity
select new
{
t1,
t2
};

if (xList.Any())
Console.WriteLine("Found");
else
Console.WriteLine("None"); //I'm looking for this result.

最佳答案

from t1 in t1datatable
join t2 in t2datatable
on t1.col1 equals t2.col1
where t1.col2 <= t2.col2
select new
{
t1,
t2
};

关于c# - 多个 linq 连接但不同的运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12841168/

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