I need to implement 3 public methods that all rely on the same initial join. Would a solution like the one described below work?
The code below is an example, the real stuff is much more complicated, that's why I want to reuse it.
private Tuple<Customer,Order> GetCustomerOrders()
{
from c in customers
join o in orders
on c.customerid equals o.customerid
select Tuple.Create(c, o)
}
public MyCustomerOrder GetCustomerOrder(int customerId)
{
return (from co in GetCustomerOrders()
where co.Item1.customerid == customerId
select new MyCustomerOrder(co.Item1, co.Item2)).FirstOrDefault();
}
public IEnumerable<MyCustomerOrder> GetCustomerOrders()
{
return from co in GetCustomerOrders()
orderby co.Item1.Name
select new MyCustomerOrder(co.Item1, co.Item2);
}
The question is, does the tuple break the query? In other words, will this end up in the SQL query that gets generated where co.Item1.customerid == customerId
?