G
Guest
Question concerning deferred evalution. If one has a customer table
and an orders table in the database and the latter table has a customer
id assocatiated with it, when a query is executed like this:
IEnumerable<Customer> customers = from c in db.Customers
where c.CustomerId == customerId
select c
Customer[] arrCust = customers.ToArray<Customer>();
Customer cust = arrCust[0];
All of the orders for the customer are apparently loaded as well. Is
there a way to NOT get all of the orders until a later time, say if you
want just the customer data on one page, and when an orders button is
pressed and another page is requested, then select the orders for that
particular customer in the other page?
If I enumerate the customers collection without executing the query by
calling ToArray and just return the first customer, the orders
collection is still populated.
foreach(Customer c in customers)
{
// For test.
return c;
}
c.Orders collection is still filled.
How is this different from using the Including statement,
customers.Including(c => c.Orders) if they both get all the data
anyways?
Apparently, deferred query execution is not making sense to me because
it looks like nothing is deferred.
Thanks,
Hammad
and an orders table in the database and the latter table has a customer
id assocatiated with it, when a query is executed like this:
IEnumerable<Customer> customers = from c in db.Customers
where c.CustomerId == customerId
select c
Customer[] arrCust = customers.ToArray<Customer>();
Customer cust = arrCust[0];
All of the orders for the customer are apparently loaded as well. Is
there a way to NOT get all of the orders until a later time, say if you
want just the customer data on one page, and when an orders button is
pressed and another page is requested, then select the orders for that
particular customer in the other page?
If I enumerate the customers collection without executing the query by
calling ToArray and just return the first customer, the orders
collection is still populated.
foreach(Customer c in customers)
{
// For test.
return c;
}
c.Orders collection is still filled.
How is this different from using the Including statement,
customers.Including(c => c.Orders) if they both get all the data
anyways?
Apparently, deferred query execution is not making sense to me because
it looks like nothing is deferred.
Thanks,
Hammad