New Posts New Posts RSS Feed: Computed Properties when fetching Async
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Computed Properties when fetching Async

 Post Reply Post Reply
Author
LowOrbit View Drop Down
Newbie
Newbie


Joined: 17-Aug-2007
Location: United States
Posts: 20
Post Options Post Options   Quote LowOrbit Quote  Post ReplyReply Direct Link To This Post Topic: Computed Properties when fetching Async
    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!
 
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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. 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down