Print Page | Close Window

Computed Properties when fetching Async

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3755
Printed Date: 21-Aug-2025 at 7:03pm


Topic: Computed Properties when fetching Async
Posted By: LowOrbit
Subject: Computed Properties when fetching Async
Date Posted: 01-Nov-2012 at 12:36pm
I have a property on an entity called PathName. This property is not mapped to a field in the database. It will return a string value similar to below:
 
Entity1.Name -> Entity2.Name -> Entity3.Name -> this.Name
 
The property would be on "this". I am using Async by default for all queries. When NOT using Async, I can simply return the value as such:
 
return string.Format("{1} {0} {2} {0} {3} {0} {4}", "->",
    this.Entity3.Entity2.Entity1.Name,
    this.Entity2.ENtity1.Name,
    this.Entiity1.Name,
    this.Name;
 
If I do this with Async on by default, Entity1, 2, and 3 are not available immediately and the string is returned imcomplete. How would I code these kinds of "computed" properties where the property has to fetch data from other related entities (potentially through a complex query)?
 
I know if I create a query for "this" and put Includes for Entity1, 2 and 3, this will work properly but that requires the developer to know to include those properties on every query.
 
I am using the Repository pattern from Coctail if that helps any and usually use the FindAsync method to get various lists of "this". Again, what would the recommended way to getting these entities without the developer having to always include the additional Includes?
 
Thanks!
 



Replies:
Posted By: mgood
Date Posted: 01-Nov-2012 at 5:57pm
Don't put something like this into the entity itself. It gets messy. You'll have to wait for each navigation to complete before you can walk the next level down. 

This is something that belongs into a service on the unit of work as an asynchronous method. The method will retrieve all the necessary data and return the value asynchronously. 



Print Page | Close Window