SelectMany - Multiple from

Query
public void Linq18()
{
List customers = GetCustomerList();

DateTime cutoffDate = new DateTime(1997, 1, 1);

var orders =
from c in customers
where c.Region == "WA"
from o in c.Orders
where o.OrderDate >= cutoffDate
select new { c.CustomerID, o.OrderID };

ObjectDumper.Write(orders);
}
Lambda Expression
public void DataSetLinq18()
{
var customers = testDS.Tables["Customers"].AsEnumerable();
var orders = testDS.Tables["Orders"].AsEnumerable();
DateTime cutoffDate = new DateTime(1997, 1, 1);

var myOrders =
customers.Where(c => c.Field("Region") == "WA").SelectMany(c => orders, (c, o) => new {c, o})
.Where(@t => @t.c.Field("CustomerID") == @t.o.Field("CustomerID") && (DateTime) @t.o["OrderDate"] >= cutoffDate)
.Select(@t => new {
CustomerID = @t.c.Field("CustomerID"),
OrderID = @t.o.Field("OrderID")
});

ObjectDumper.Write(myOrders);
}
Output
CustomerID=LAZYK OrderID=10482
CustomerID=LAZYK OrderID=10545
CustomerID=TRAIH OrderID=10574
CustomerID=TRAIH OrderID=10577
CustomerID=TRAIH OrderID=10822
CustomerID=WHITC OrderID=10469
CustomerID=WHITC OrderID=10483
CustomerID=WHITC OrderID=10504
CustomerID=WHITC OrderID=10596
CustomerID=WHITC OrderID=10693
CustomerID=WHITC OrderID=10696
CustomerID=WHITC OrderID=10723
CustomerID=WHITC OrderID=10740
CustomerID=WHITC OrderID=10861
CustomerID=WHITC OrderID=10904
CustomerID=WHITC OrderID=11032
CustomerID=WHITC OrderID=11066
Related Tutorial