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 4026434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:58:12+00:00 2026-05-20T10:58:12+00:00

What do you think about mixing Repository and Active Record patterns like below? How

  • 0

What do you think about mixing Repository and Active Record patterns like below?

How would you implement the GetAll() method regarding there is an inheritance envolved?

class Person
{
    public int Id { get; set; }
    public string Name { get; set; }

    public Person(int id)
    {
        this.Id = id;
        new PersonRepository().Load(this);
    }

    public virtual void Save()
    {
        new PersonRepository().Save(this);
    }
}

class Employee : Person
{
    public int RegistrationNumber { get; set; }

    public Employee(int id) : base(id)
    {
        new EmployeeRepository().Load(this);
    }

    public override void Save()
    {
        base.Save();
        new EmployeeRepository().Save(this);
    }
}

interface IRepository<T>
{
    void Save(T x);
    bool Load(T x);
    IEnumerable<T> GetAll();
    // Other methods removed to keep code clean
}

class PersonRepository : IRepository<Person>
{
    public void Save(Person x)
    {
        throw new NotImplementedException();
    }

    public bool Load(Person x)
    {
        throw new NotImplementedException();
    }

    public IEnumerable<Person> GetAll()
    {
        throw new NotImplementedException();
    }
}

class EmployeeRepository : IRepository<Employee>
{
    public void Save(Employee x)
    {
        throw new NotImplementedException();
    }

    public bool Load(Employee x)
    {
        throw new NotImplementedException();
    }

    public IEnumerable<Employee> GetAll()
    {
        // How to return Person data????
        throw new NotImplementedException();
    }
}
  • 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-20T10:58:13+00:00Added an answer on May 20, 2026 at 10:58 am

    If you’re worried about incurring the overhead of loading all the Person objects then maybe don’t load them until you actually need the data – such as via the Lazy Load approach.

    If you needed to populate a list of “People” but didn’t want to bring back ALL their data – only the stuff needed for the list (say ID, First and last name) then do only that – maybe using the Person object isn’t the right way to go as it’s too heavy?

    What I tend to do is have a concept in mind (like person) and have two classes that represent them:
    – A lightweight class designed for lists, etc, typically read-only.
    – A “full featured” object for when performing operations on a “Person”.

    Architecturally there’s nothing wrong with what you’re doing but it’s strictly OO based – its not concerned with implications of data retrieval in terms of physical limitations that might be placed on you by the environment the software will actually run in.

    basically the approach you have is great but is based on a “per class” approach rather than a set-based one.

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

Sidebar

Related Questions

I would like to code a shelf and I don't want to think about
How do you think about data access code like this: public void AddCusotmer(Cusotmer customer)
I'd like know what people think about using RAISERROR in stored procedures to pass
I'd like to know what you think about this part of our program is
Think about a speedometer, and imagine all these little strokes around it like 10
think about an array like this: ... key1 => some_call(val1, $params), key2 => some_call(val1,
Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
What do you think about this build tool ? I'm thinking of migrating from
When you think about it, doesn't the REST paradigm of being resource-oriented boil down
What do you guys think about this for a generic singleton? using System; using

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.