New Posts New Posts RSS Feed: Adding optional includes on Repository<> WithIdAsync() method
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Adding optional includes on Repository<> WithIdAsync() method

 Post Reply Post Reply
Author
JohnBloom View Drop Down
Groupie
Groupie
Avatar

Joined: 30-Nov-2010
Location: Topeka, KS
Posts: 95
Post Options Post Options   Quote JohnBloom Quote  Post ReplyReply Direct Link To This Post Topic: Adding optional includes on Repository<> WithIdAsync() method
    Posted: 24-Apr-2012 at 10:46am

I really like the WithIdAsync function on the generic repository class. It has saved me from writing a bunch of little functions to load items by id. I noticed that FindAsync has the ability to add includes to it. There is often times when we want to include something when we load one item as well. Is this possible to do now or is this a feature request*?

*I realize that this question refers to the contrib library and if it is a feature I might be willing to jump in there and figure it out. As of now I have been head down moving through our transition to Cocktail** so I havent had time to figure the whole Git thing out.


**As a futher aside we just released our changes to our customers! Cocktail FTW!

-John Bloom
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: 24-Apr-2012 at 12:26pm
John,
The idea behind WithIdAsync is that it always fetches the entity graph consistently per UoW type. In your specifc UoW you can use a subclass of Repository<T> and redefine the query you want it to use by overriding the GetKeyQuery method. I've done that in TempHire for example.
 
In places where you need to retrieve an entity by ID with a non-standard query, you would use FindAsync instead or actually define a different UoW type configured with a repository serving the purpose for that area of the application. Don't be shy about creating different UoW types optimized for the various areas and workflows of your application.
 
    public class StaffingResourceRepository : Repository<StaffingResource>
    {
        public StaffingResourceRepository(IEntityManagerProvider<TempHireEntities> entityManagerProvider)
            : base(entityManagerProvider)
        {
        }
 
        public new TempHireEntities EntityManager
        {
            get { return (TempHireEntitiesbase.EntityManager; }
        }
 
        protected override IEntityQuery GetKeyQuery(params object[] keyValues)
        {
            return EntityManager.StaffingResources
                .Where(r => r.Id == (Guid) keyValues[0])
                .Include(r => r.Addresses)
                .Include(r => r.PhoneNumbers);
        }
    }
 


Edited by mgood - 24-Apr-2012 at 12:34pm
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: 24-Apr-2012 at 12:27pm
Oh BTW, congrats on the release.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down