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.
Loading of Multiple Associated Classes Fails?
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...
---------------------------------------------------------
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...