How would I express the following in LINQ?
select * from table_1 t1
join table_2 t2 on t1.col1 = t2.col1 and t1.col2 <= t2.col2
Here’s what I’ve tried, but I’m not getting the desired results. I’m trying to join
the 2 tables but since table_1 quantity is not greater or equal than what’s in table_2 quantity for WidgetA
I wouldn’t expect there to be any records in the results (in 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.
1 Answer