Trips to the database
I have a general performance question that needs clarification. Assuming an object graph of Customer, Orders, OrderDetails and assume I am retrieving one customer with 10 orders and each order has 5 orderdetails, how many trips to the database will be required? Is it 3 or 12?
Thanks,
Dave Foderick
Deferred execution will run more queries, but will only do it when needed. This is the default for most things you have seen, most likely. For example, in the following LINQ query, a SQL query will be fired for each customer to get the orders for that customer:
var q = from c in db.Customers select new {c.CustomerID, c.Orders};
ObjectDumper.Write(q, 1);
Immediate execution will run the queries in 1 round trip, and return the populated object graph to you in one trip. You can tell DLINQ to use Immediate execution by using the Including operator, which looks something like this:
var q = (from c in db.Customers select new {c.CustomerID, c.Orders}).Including(c => c.Orders);
ObjectDumper.Write(q, 1);
Including() can be nested to force loading the entire graph.
Hope that helps.
Dan Miser
I'm talking about the non-deferred case. I'm also talking about non-projection where the relationship between customers and orders is specified in the attributes or generics, after all the whole point of OR Mapping is to do declarative, not imperative, programming.
I'm highly sceptical that (d)linq knows which orderdetails to load apriori. I guess I'll have to try it myself.
-Dave Foderick