DataLoadOptions weird behaviour
Posted: Wed 08 Sep 2010 16:37
When I create first instance of my DataContext I use DataLoadOptions to load children elements (Orders). On the next step I create second instance of datacontext and new DataLoadOptions using DataLoadOptions as before with added second children collection (OrderDetails).
In the first case collection is loaded with desired data, but in the second case only first collection is filled out but the second one remains empty.
Note that HasLoadedOrAssignedValues property is not always set to true despite there are some data in the collection.
Example:
Variable q2 loads only customer orders, but orderdetails are empty.
It looks like datacontext remeber the last DataLoadOptions for the same query extended with loading orderdetails collection.
In the first case collection is loaded with desired data, but in the second case only first collection is filled out but the second one remains empty.
Note that HasLoadedOrAssignedValues property is not always set to true despite there are some data in the collection.
Example:
Code: Select all
MyOracleDataContext db1 = new MyOracleDataContext();
db1.DefferedLoadingEnabled = false;
DataLoadOptions opts1 = new DataLoadOptions();
opts1.LoadWith(p => p.Orders);
db1.LoadOptions = opts1;
var q1 = (from p in db.Customers
select p).ToList();
MyOracleDataContext db2 = new MyOracleDataContext();
db2.DefferedLoadingEnabled = false;
DataLoadOptions opts2 = new DataLoadOptions();
opts2.LoadWith(p => p.Orders);
opts2.LoadWith(p => p.OrderDetails);
db2.LoadOptions = opts2;
var q2 = (from p in db2.Customers
select p).ToList();
It looks like datacontext remeber the last DataLoadOptions for the same query extended with loading orderdetails collection.