Home

Example of OnDemand with join?

edited May 2014
I have seen LINQ query expressions that use OnDemand between tables tat have foreign keys. If I'm trying to build a similar OnDemand query expression for tables using joins, can someone give me an example of one?

edit:
using the LinqPad "what's new" page example
from c in Customers
let bigSales = c.SalesOrderHeaders.Where (soh => soh.TotalDue > 100000)
where bigSales.Any()
select new
{
	c.Store.Name, 
	BigSales = bigSales.OnDemand()
}
How would you rewrite the query if there were no foreign keys between Customers and SalesOrderHeaders/Store?

Comments

  • I'm sorry I don't use query syntax anymore. And I'm assuming the column names:
    Customers
    .Select(a => new
    {
        c.Store.Name,
        BigSales = SalesOrderHeaders
                   .Where (soh => soh.SalesOrderHeaderId == a.SalesOrderHeaders 
                                  && soh.TotalDue > 100000)
    })
    .Where(a => a.BigSales.Any())
    .Select(a => new{a.Name, BigSales = a.BigSales.OnDemand()})
    Just a note, OnDemand has the benefit of lazy-execution and aesthetics. Here, since BigSales is being used in the filter, you'll experience eager execution.
Sign In or Register to comment.