我将如何在 LINQ 中表达以下内容?
select * from table_1 t1
join table_2 t2 on t1.col1 = t2.col1 and t1.col2 <= t2.col2
这是我尝试过的,但我没有得到想要的结果。我正在尝试加入 2 个表,但由于table_1
数量不大于或等于table_2
数量,因为WidgetA
我不希望结果中有任何记录(在 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.