public void Linq16() {
List customers = GetCustomerList();
var orders =
from c in customers,
o in c.Orders
where o.OrderDate >= new DateTime(1998, 1, 1)
select new {c.CustomerID, o.OrderID, o.OrderDate};
ObjectDumper.Write(orders);
}
SelectMany - from Assignment
public void Linq17() {
List customers = GetCustomerList();
var orders =
from c in customers,
o in c.Orders,
total = o.Total
where total >= 2000.0M
select new {c.CustomerID, o.OrderID, total};
ObjectDumper.Write(orders);
}
SelectMany - Multiple from
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);
}
SelectMany - Indexed
public void Linq19() {
List customers = GetCustomerList();
var customerOrders =
customers.SelectMany(
(cust, custIndex) =>
cust.Orders.Select(o => "Customer #" + (custIndex + 1) +
" has an order with OrderID " + o.OrderID) );
ObjectDumper.Write(customerOrders);
}
Partitioning Operators
Take - Simple