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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:38:10+00:00 2026-05-23T15:38:10+00:00

Let just say I have the following data models: public class Account { public

  • 0

Let just say I have the following data models:

public class Account
{
   public string Username { get; set; }
   public string Password { get; set; }
}

public class Configuration
{
   public string Key { get; set; }
   public string Value { get; set; }
}

For now, each of them has their own repository for data access, and uses entity framework as its unit of work/DbContext. I’m planning to pull out the Configuration part out of the entity frame and use Redis or Memcached as its data access. I might even to switch the EF to NHibernate or no ORM at all, and I might switch the database to MongoDB or CouchDB.

What is the good way to do this? To be ignorant of all those lower layer stuff in my business logic? What kind of pattern to use? Is it possible or is it just bad things to design for changes like this?

Thanks 🙂

  • 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-23T15:38:11+00:00Added an answer on May 23, 2026 at 3:38 pm

    As stated in the previous post, you should go the “way of the Interface”.
    I personally do not implement directly the repository for each orm but I use a little variation.
    Using your example…

    public interface IAccountRepository
    {
      Account Get(int id);
      void Delete(int id);
      ...other method...
    }
    

    then you create your repository

    public class AccountRepository : IAccountRepository
    {
       private readonly IUnitofWork unitofWork;
    
       public AccountRepository(IUnitofWork unitofWork)
       {
          this.unitofWork = unitofWork;
       }
    
       //Implement interface method
       public Account Get(int id)
       {
          //some logic or just the call to the unit of work
          return unitofWork.Get(id);
       }
    }
    

    I am happy with this solution because I end up with only one repository that 90% of the time use linq to query so I don’t have to write the sql for each unit of work and every time I have to write a “GetAllProducts” with paging I do not have to write the same code (and tests) for every unit of work, but only for my repository. This is a simple example obviously so I hope you get the idea.
    You can make a RepositoryBase that implement a method Find() or Query() which use linq.
    Then with your Castle Windsor or ninject or whatever you can inject the unit of work you prefer. Hope it helps.

    Update:
    a sample of my UnitofWorkBase that implement nhibernate is something similar:

    public class NHUnitofWork<T> : IUnitofWork<T> where T : EntityBase
    {
    protected INHSessionBuilder SessionBuilder { get; private set; }
    
    public NHPersistorBase(INHSessionBuilder sessionBuilder)
    {
      SessionBuilder = sessionBuilder;
    }
    
    public T Get(int id)
    {
      T result = null;
      ISession session = SessionBuilder.GetSession();
      using (ITransaction transaction = session.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
      {
        try
        {
          result = (T)session.Get(typeof(T), id);
          transaction.Commit();
        }
        finally
        {
          if (transaction.IsActive)
            transaction.Rollback();
        }
      }
      return result;
    }
    public IQueryable<T> Find()
    {
      return SessionBuilder.GetSession().Query<T>();
    }
    

    }

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

Sidebar

Related Questions

Let's say I have the following class: class MyClass { private: int Data; public:
I've been having this bothering recurring theme; let's just say, I have a class
Let's say I have a database filled with people with the following data elements:
Let's say I have the following data model, for keeping track of the stats
Let's say we get the following data from a CSV file: account_number balance customer
Let's say I have a Rectangle class like so: class Rectangle { public: double
Let's say I have this simple structure class FooDefinition { public FooDefinition Parent {
First, let me just say that I have searched for information on this topic;
Let's say I have a file named output1 How to match just digits form
Let's say I have css1.css and css2.css. Just for the sake of keeping files

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.