Lazy Loading not working

Posts   
 
    
Icemokka
User
Posts: 3
Joined: 21-Oct-2010
# Posted on: 21-Oct-2010 11:08:24   

Hi,

I've got a test project for EF 4.0, we are considering buying LLBLGen Pro very soon.

When generating the V1 code, lazy loading works as it should. But when I choose to create an EF4 POCO Self-tracking solution, lazy loading does not work. In my example, it always returns 0 as count for CostBudgets.Count. And Can I force a load on a POCO-object (the .Load method does not exist)?

  OCWEF4DataContext newContext = new OCWEF4DataContext(GetEntityConnection());

  newContext.ContextOptions.LazyLoadingEnabled = true;

  //List<CostCenter> cc = newContext.CostCenters.ToList();
  foreach (Systemat.Software.OCW.EntityClasses.CostCenter item in newContext.CostCenters)
  {
    System.Diagnostics.Trace.WriteLine(item.CostCenterName.ToString());
    //item.CostBudgets.Load();
    System.Diagnostics.Trace.WriteLine(item.CostBudgets.Count().ToString());
  }

This same example in the project EF4.0 v1, the lazy loading & load function works as it should. I'm pretty sure lazy loading is supported on POCO-classes in EF4. I also tried checking the EnableProxyCreationOnContext, but that didn't help either.

Any idea's ???

Regards, Sven Peeters

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Oct-2010 11:36:18   

Please check the following for explictly loading child objects: http://msdn.microsoft.com/en-us/library/dd468074.aspx

Icemokka
User
Posts: 3
Joined: 21-Oct-2010
# Posted on: 21-Oct-2010 11:46:23   

Hi,

The explicit loading is ok now, but how come we need to do this while EF should do this automatically via Lazy Loading?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 21-Oct-2010 12:40:46   

to load explicitly, please check the EF documentation on poco's: http://msdn.microsoft.com/en-us/library/dd456855.aspx

Lazy loading should work, however .Count() is not the same as .Count. It's not said that .Count() will load all elements and then do an in-memory count (as that would in fact be very inefficient, as a db-scalar query is more efficient).

We'll look into it to see if we can reproduce it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39905
Joined: 17-Aug-2003
# Posted on: 21-Oct-2010 12:58:03   

POCO STE (Self tracking entities)'s don't support lazy loading: http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/6133d1a8-5952-4168-bcb6-756202341238

The normal POCO classes should though, and indeed do, when I use normal POCO's and enable proxies, lazy loading occurs as normal.

So you should either look into using normal POCOs (the POCO templates we provide, not the Selftracking entity poco's) or not use lazy loading.

Frans Bouma | Lead developer LLBLGen Pro
Icemokka
User
Posts: 3
Joined: 21-Oct-2010
# Posted on: 21-Oct-2010 14:04:51   

That is a clear answer, thank you for the info