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

The Archive Base Latest Questions

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

I’m trying to understand the Repository Pattern , while developing an ASP.NET MVC application

  • 0

I’m trying to understand the Repository Pattern, while developing an ASP.NET MVC application (using .NET 3.5, ASP.NET MVC 1.0 and Entity Framework). I’ve gotten far enough to get the dependency injection and all working with one Controller and one Entity type, but now I’ve gotten as far as to implementing support for a relation between different types, and I’m stuck.

In all examples I’ve seen, the repository interface is called something like IContactsRepository, and contains (CRUD) methods that are concerned with Contact items only. I want to implement grouping of Contacts, so I have an entity type called Group, and an IGroupRepository interface for handling (CRUD) operations on groups.

  • Where does a method belong that is concerned with more than one entity type (in this case for example the method AddToGroup, that adds a Contact to a Group)?

I made an attempt at a larger inheritance structure for repositories, where I created the following interfaces:

ITypedRepository<T>
{
    IEnumerable<T> GetAll();
    T Get(int id);
    bool Add(T newObj);
    bool Edit(T editedObj);
    bool Delete(int id);
}

IContactsRepository : ITypedRepository<Contact> { }

IGroupsRepository : ITypedRepository<Group> {
    bool AddToGroup(int contactId, int groupId);
}

IRepository : IContactsRepository, IGroupsRepository

I then tried to create a master repository that inherits IRepository, as follows:

public class EntitiesRepository : IRepository
{
    IEnumerable<Contact> IRepository<Contact>.Get()
    {
        throw new NotImplementedException();
    }
    IEnumerable<Group> IRepository<Group>.Get()
    {
        throw new NotImplementedException();
    }
    // Etc. All methods were generated by hitting [Ctrl]+[.] with the cursor on
    // the interface inheritance reference to IRepository and selecting
    // "Explicitly implement IRepository"
}

As soon as I try to call one of the methods in the Repository from my Controller with this code

var contacts = _repository.Get();

I get a build error message about ambiguity between Get<Contact>() that was inherited via IContactsRepository and Get<Group>() that came via IGroupsRepository. I have understood that this is not allowed because the IRepository inherits the same generic interface with different types (see example 5 in the linked article).

  • Now, since I inherit via other interfaces, is there any chance I could “override the names” of these methods, for example like below?

    IContactsRepository : ITypedRepository<Contact>
    {
        IEnumerable<Contact> GetContacts = ITypedRepository<Contact>.Get();
        ...
    }
    

That way, I can access it from IRepository.Getcontacts without any ambiguity. Is it possible, or is there any workaround to this problem?

And a new question, for clarification:

  • Is there anyway to specify in the call from the controller which of the Get() methods I want?

  • What is the best way to tackle my initial problem – the need of a repository that handles a lot of things, instead of just one entity type?

EDIT: Added code example of Repository class and call from Controller.

  • 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-13T09:06:21+00:00Added an answer on May 13, 2026 at 9:06 am

    I think you don’t need all this complexity. When you add a contact to a group you are changing the group. I assume you have a collection of contacts on Group class. After adding a contact into a group, simply you need to save the group. So do you really need a AddContactToGroup method, just a Save method on Group repository interface would do the same job. Also you don’t need a new method for every new relational property on Group.

    For the implementation of the Save method itself, if you use NHibernate, only thing you need to do is to call relevant method.

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

Sidebar

Ask A Question

Stats

  • Questions 382k
  • Answers 382k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer IMO counting lines of code is a terrible quality metric.… May 14, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer That's not blurred text, it's called a "watermark." You can… May 14, 2026 at 10:29 pm
  • Editorial Team
    Editorial Team added an answer In my opinion, a Rich Internet Application only makes sense… May 14, 2026 at 10:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.