Page 1 of 1

Loading of Multiple Associated Classes Fails?

Posted: Thu 09 Jul 2009 11:29
by crazypit
Hello,

I use the following DataLoadOptions:

DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith(c => c.CaseType);
dlo.LoadWith(c => c.Events);
dataContext.LoadOptions = dlo;

Case has a One To Many Association to Case Type (One = Case Type) and to Event (One = Case). I want to load the associated CaseType AND the associated Events. Nevertheless, only the first referenced Entity is loaded. If i run the aforementioned code, only the CaseType association is loaded. If i comment out the relevant line, then the Events association is loaded. I also checked the results with the The Log of the DataContext.

Posted: Fri 10 Jul 2009 08:38
by AndreyR
We will investigate this behaviour.
I will let you know about the results of our investigation.

Posted: Thu 16 Jul 2009 13:24
by crazypit
Any news on that? Latest version do not seem to fix the problem...

Posted: Thu 16 Jul 2009 14:45
by AndreyR
Sorry, but this problem will not be fixed.
Neither LINQ to Oracle, nor LINQ to SQL support the loading of two or more associations in the described way.
The implementation of such behaviour will result in an enormous performance loss.

Posted: Thu 16 Jul 2009 15:01
by crazypit
Here is an excerpt from the book Pro LINQ in c# 2008 from APress:

---------------------------------------------------------
Immediate Loading of Multiple Associated Classes
With the DataLoadOptions class, it is possible to instruct it to immediately load multiple associated
classes of an entity class.
Notice that in Listing 14-9, the generated SQL query made no reference to the customer’s associated
customer demographics. Had I referenced the customer demographics on the retrieved customers,
additional SQL statements would have been executed for each customer whose customer demographics
were referenced.
In Listing 14-10, I will instruct the DataLoadOptions to immediately load the customer’s customer
demographics as well as its orders.
Listing 14-10. Immediately Loading Multiple EntitySets
Northwind db = new Northwind(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind");
DataLoadOptions dlo = new DataLoadOptions();
dlo.LoadWith(c => c.Orders);
dlo.LoadWith(c => c.CustomerCustomerDemos);
db.LoadOptions = dlo;
IQueryable custs = (from c in db.Customers
where c.Country == "UK" &&
c.City == "London"
orderby c.CustomerID
select c);
// Turn on the logging.
db.Log = Console.Out;
foreach (Customer cust in custs)
{
Console.WriteLine("{0} - {1}", cust.CompanyName, cust.ContactName);
}
-----------------------------------------------

The only difference from my example is that i try to load an EntityRef and an EntitySet property where the book tries to load 2 EntitySet properties...

Posted: Thu 16 Jul 2009 15:06
by crazypit
The text in the book, do not make any assumptions about the type of associations. It generally says about loading of multiple associations. It gives the idea, that i can load as many as i want...

Posted: Fri 17 Jul 2009 12:38
by AndreyR
Thank you for your help. We have found and fixed the problem, the fix will be available in the next build.
My previous post dealt with optimization of these queries using joins, it still will not be available.