FetchMode.Join issues with 3-tier hierarchy
Posted: Fri 01 Jul 2011 21:51
DataLoadOption with FetchMode.Join does not seem to be reliably loading child entities. We have a 3 tiered hierarchy: top level of ClientSetup entity with many children Category entities and each Category has many child Action entities. Each level of the hierarchy also has matching text descriptions that can contain one row for each language (typically only English). Setting up the DataLoadOptions looks like this:
DataLoadOptions dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith(s => s.SetupTexts, FetchMode.Join);
dataLoadOptions.LoadWith(s => s.Categories, FetchMode.Join);
dataLoadOptions.LoadWith(c => c.CategoryTexts, FetchMode.Join);
dataLoadOptions.LoadWith(c => c.Actions, FetchMode.Join);
dataLoadOptions.LoadWith(a => a.ActionTexts, FetchMode.Join);
db.LoadOptions = dataLoadOptions;
db.DeferredLoadingEnabled = false;
var qry = (from s in db.ClientSetups
where s.Setupkey == setupKey
select new
{
ClientSetup = s
});
return qry.FirstOrDefault().ClientSetup;
The immediate children of ClientSetup load fine, but the next level down does not. The “CategoryTexts” don’t load at all – even though there is data in the database. Actions do load.
The strange thing is, if we switch the two lines like so:
dataLoadOptions.LoadWith(c => c.Actions, FetchMode.Join);
dataLoadOptions.LoadWith(c => c.CategoryTexts, FetchMode.Join);
Now CategoryText loads fine and Actions do not.
I used DBMonitor to track what’s generated and all the data is indeed being fetched. It just doesn’t appear to all be making its way into my entity objects.
This sounds like a bug – or am I missing something about how I am coding this?
DataLoadOptions dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith(s => s.SetupTexts, FetchMode.Join);
dataLoadOptions.LoadWith(s => s.Categories, FetchMode.Join);
dataLoadOptions.LoadWith(c => c.CategoryTexts, FetchMode.Join);
dataLoadOptions.LoadWith(c => c.Actions, FetchMode.Join);
dataLoadOptions.LoadWith(a => a.ActionTexts, FetchMode.Join);
db.LoadOptions = dataLoadOptions;
db.DeferredLoadingEnabled = false;
var qry = (from s in db.ClientSetups
where s.Setupkey == setupKey
select new
{
ClientSetup = s
});
return qry.FirstOrDefault().ClientSetup;
The immediate children of ClientSetup load fine, but the next level down does not. The “CategoryTexts” don’t load at all – even though there is data in the database. Actions do load.
The strange thing is, if we switch the two lines like so:
dataLoadOptions.LoadWith(c => c.Actions, FetchMode.Join);
dataLoadOptions.LoadWith(c => c.CategoryTexts, FetchMode.Join);
Now CategoryText loads fine and Actions do not.
I used DBMonitor to track what’s generated and all the data is indeed being fetched. It just doesn’t appear to all be making its way into my entity objects.
This sounds like a bug – or am I missing something about how I am coding this?