New Posts New Posts RSS Feed: Lazy Loading
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Lazy Loading

 Post Reply Post Reply
Author
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Topic: Lazy Loading
    Posted: 10-Oct-2012 at 8:20am
I am building a WinRt app. I have a Web Server component storing my DataModel and a seperate winrt library project holding the winrt version of the app, similar to how silverlight is done.

I noticed that when I set my models LazyLoading property to false it still lazy loads. I have tried rebuilding the project as well as restarting iis. Nothing changes the outcome. I do not want lazy loading.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 8:33am
My guess is you're setting the "Lazy Loading Enabled" property within the EDM Designer.   DevForce doesn't actually use this setting, it's used by EF in an EF only model.  Confusing, I know, but this was true in DevForce 2010 as well.
 
The correct way to turn lazy loading within DevForce off is via the EntityReferenceStrategy.  More here - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/navigation-properties-data-retrieval
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 8:47am
Thank you for this response. This fixed the lazy loading issue but now when I do the following the Included properties don't load:

return await EntityManager.ContactEmails
                .Where(e => e.InActive == false && e.ContactId == pContactId)
                .Include(e => e.Email)
                .ExecuteAsync();

EntityManager.DefaultEntityReferenceStrategy = new EntityReferenceStrategy(EntityReferenceLoadStrategy.Load, MergeStrategy.OverwriteChanges, true);
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 8:54am
Also, even when I set to load from the datasource everytime  a specific instance still loads lazy.

I set the entire entity manager to load only from source. 
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 8:56am
Nevermind got it.
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 9:22am
OK :).
 
The EntityReferenceLoadStrategy of "Load" will always force the navigation property to be reloaded from the data source.   And when async navigation is enabled, as it will be in Windows Store apps, the resulting navigation will be a pending entity or pending entity list.
 
 
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 9:25am
To resolve I set load strategy on my entire EntityManager to EntityReferenceLoadStrategy.DoNotLoad.

When I run: 

 return await DataService.EntityManager.OrganizationContactAssociations
                .Where(e => e.InActive == false && e.ContactId == pContactId)
                .ExecuteAsync();

I get the appropriate records

When I run:
 return await DataService.EntityManager.OrganizationContactAssociations
                .Where(e => e.InActive == false && e.ContactId == pContactId)
                .Include(e => e.ContactEmail)
                .Include(e => e.ContactEmail.Email)
                .Include(e => e.ContactJobTitle)
                .Include(e => e.ContactJobTitle.JobTitle)
                .ExecuteAsync();

I get nothing.

If I add 1 include I get records, 2 or more and I get nothing.

It appears that the Include is performing a join.

Can you lend me some guidance.


Edited by orcities - 10-Oct-2012 at 9:27am
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 9:44am
EF generates the SQL based on the relationships in the model, and will use inner and outer joins as needed for the Included relations.
 
I'd check the generated SQL (SQL Server Profiler is a handy tool if you're running SQL Server) to see what the generated query looks like.  If there are any inner joins, then I'd double check the definition of that relationship in the EDM.
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 10:23am
They are coming back as Inner Joins. How do i change it to be Left or Right joins? My assumptions is that an Include would only pull that data that applies, implying a left/right join, and not an inner.
Back to Top
orcities View Drop Down
Senior Member
Senior Member
Avatar

Joined: 28-Aug-2007
Location: United States
Posts: 454
Post Options Post Options   Quote orcities Quote  Post ReplyReply Direct Link To This Post Posted: 10-Oct-2012 at 10:43am
The Entity I am trying to query is an association table with a type column. The type column determines one entity it links off to. Example. OrganizationContactAssociation { OrganizationId, ContactId, Id, AssociationType }
If AssociationType = Email then Id is an EmailId and the Navigation Property for ContactEmail is the correct one to use.

Because of this I tried:
return await DataService.EntityManager.OrganizationContactAssociations
                .Where(e => e.InActive == false && e.ContactId == pContactId)
                .Include(e => e.ContactAddress)
                .Include(e => e.ContactAddress.Address)
                .Include(e => e.ContactAddress.Type)
                .Include(e => e.ContactPhone)
                .Include(e => e.ContactPhone.Phone)
                .Include(e => e.ContactPhone.Type)
                .Include(e => e.ContactJobTitle)
                .Include(e => e.ContactJobTitle.JobTitle)
                .Include(e => e.ContactEmail)
                .Include(e => e.ContactEmail.Email)
                .ExecuteAsync();

This causes an inner join on each table rather then a left join.

I tried changing the Id to allow nulls which then allows the references to be 0 to many. This causes an error.

I tried creating Entities of type OrganizationContactAssociation for each type. This does not allow me to query those sub/inherited entities directly.

I tried querying each individual type separately, this causes only the last query to be in the cache. I can not allow for the lazy load type because I have a deleted state to each entity, and do not delete any entities. Therefore, I can only display those entities where the deleted states is false.


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down