Print Page | Close Window

Async Navigational Properties

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3749
Printed Date: 13-May-2026 at 12:56am


Topic: Async Navigational Properties
Posted By: LowOrbit
Subject: Async Navigational Properties
Date Posted: 30-Oct-2012 at 11:40am
Hello
 
I am using the Cocktail framework in our application. I have created a Repository object to perform queries on an entity. For example, I have a simple query that fetches a single entity (uses WithIdAsync). This operation returns successfully. I then try to fetch another record via a navigation property of that entity. I have set the DefaultEntityReferenceStrategy to
 
new EntityReferenceStrategy(EntityReferenceLoadStrategy.Lazy, MergeStrategy.OverwriteChanges, false)
 
which basically tells DevForce to NOT use Async for navigation properties. The problem I'm running into is that any navigation properties fetched this way come back with an EntityState of Detached. Is this really supposed to be the case? Shouldn't any entities fetched via a navigation property come back as Unchanged?
 
Thanks
 
Robert



Replies:
Posted By: mgood
Date Posted: 30-Oct-2012 at 3:36pm
Silverlight or WPF? If the former, navigations are always asynchronous and in WPF they are synchronous by default. 

You might be getting the NullEntity.  http://drc.ideablade.com/xwiki/bin/view/Documentation/null-entity - http://drc.ideablade.com/xwiki/bin/view/Documentation/null-entity




Posted By: LowOrbit
Date Posted: 30-Oct-2012 at 4:26pm
This is WPF application. Since I'm using a Repository from Cocktail, all the repository methods do queries ASync. But I have overriden the DefaultEntityReferenceStrategy property and set it to NOT use async when fetching navigational properties.
 
And no, the entity I'm getting back is not a NullEntity because all the fields are populated from the database as I would expect, it's just the EntityState is saying it's Detached.
 
Also, if I fetch my main entity using the Repository and put an Include on it, the related Entity comes back as expected (not a NullEntity) but it is still Detached. It doesn't appear to make any difference whether you get the related entity via an Include or reference it by lazy loading.
 
Ultimately, I want to change my application to fetch all navigational properties using Async also. Unfortunately, we have a lot of UI that is referencing a navigational property in the UI bindings via a path (i.e.     Entity.TaskSchedule.Name). TaskSchedule in this case is a navigational property. When fetched Async, TaskSchedule comes back as a PendingEntity and the binding will show Name as blank initially. I can't seem to get the UI to refresh properly when the PendingEntity is finally complete which is why I switched all the Navigation properties to fetch syncronously.
 
Do you have an example of how to use the Repositories to fetch navigational properties?
 
Thanks!


Posted By: mgood
Date Posted: 30-Oct-2012 at 5:22pm
How are you checking if the entity is detached? The debugger is not a reliable way to inspect the EntityAspect. Use the Immediate Window to check the entity state.
 
Read the last paragraph in my best practices blog post for advise on navigation properties.
 
http://cocktail.ideablade.com/best-practices-for-the-real-world/ - http://cocktail.ideablade.com/best-practices-for-the-real-world/



Print Page | Close Window