Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4268200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:00:13+00:00 2026-05-21T07:00:13+00:00

I have some trouble with the repository pattern. Or maybe just some unclear points.

  • 0

I have some trouble with the repository pattern. Or maybe just some unclear points. For sake of these questions I have a simple example domain with two entity aggregates.

public class Category
{
  string Name {get;set;}
  Category Parent {get;set;}
  IList<Category> Children {get;set;}
}

public class Transaction
{
  Category Owner {get;set;}
  string Name
  ... bla bla
}

In this particular Domain model these two do not form a single aggregate. As such, I have two standard IRepository implementations for each of the two entities.

Question One: When dealing with validation, such as deletion of a category, a repository needs to do relational checks. Is it a common practise that repositories talk (and as such are injected with references) to other repositories and generate errors, thus keeping it neatly disconnected from the other layers or do they delegate this to the database layer?

Question Two: Similarly, when updating an entity (aggregate) often save/change/delete validation needs to be done on various components. Presumably this is only reasonably doable when you have a unit of work that buffers changes and only commits when all validation succeed?

Question Three: Loading a single category results in an entire object tree to be loaded when not using lazy loading. To limit this the only real option is to implement lazy loading and/or change tracking in your entities?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:00:14+00:00Added an answer on May 21, 2026 at 7:00 am

    For all your three questions I would recomend you to implement UnitOfWork pattern. I ususaly implement IUnitOfWork that is a part of my repositories. When I want to work with more then one of my repositories I inject (the same) UnitOfWork into all I want to work with (That is just one of the ways that I prefer). Then when all work is done I call Commit() on my UnitOfWork which does savechanges on entity frameworks context. UnitOfWork is wrapper around entity frameworks context.

    Question one: Relational checks are done by database. If something fails entity framework will throw exception and you should handle it in you higher app layer, lets call it service layer where you work with your UnitOfWork.

    Question two: Use UnitOfWork pattern.

    Question three: You should use lazy loading if you dont want to load the whole object tree.

    Repository:

        public interface IRepository<T>
    {
        IUnitOfWork UnitOfWork { get; set; }
        IQueryable<T> All();
        void Delete(T item);
        void Save(T item);
        void Update(T item);
        IQueryable<T> Find(Func<T, bool> expression);
        void Attach(T item);        
    }
    

    UnitOfWork:

        public interface IUnitOfWork : IDisposable
    {
        ObjectContext Context { get; set; }
        void Commit();
        bool LazyLoadingEnabled { get; set; }
        bool ProxyCreationEnabled { get; set; }
        string ConnectionString { get; set; }
    }
    

    OR here is very simle implementation of UnitOfWork pattern to get you started(Its a bit different from what i described UnitOfWork contains Repositories mine is the other way around…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm migrating to Nhibernate 2.0 GA but have some trouble with setting cache expirations
I am developing a small windows app, but have some trouble deciding whether to
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am having some trouble with the Google Maps API . I have an
I have created some rounded navigation tabs using CSS and am having trouble when
I have some trouble with regex and php here: <span style=color: blue>word1</span> word by
I have some trouble for choosing the right type of exception to throw when
I am have some trouble specifying a custom icon in my WPF applicaion. I
I'm getting some trouble binding a date from QueryString : I have the following
I have some trouble getting the VCS of teamcity work. I'm using perforce and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.