Skip to main content
added 966 characters in body
Source Link
Shyju
  • 1.5k
  • 1
  • 9
  • 6

I don't see any reason for the Repository pattern to not work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/XML/web service), it is good to have an abstraction layer. The Repository pattern works well in this scenario. I do not believe that Entity Framework is enough abstraction to hide what goes on behind the scenes.

I have used the Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the DbContext with a Repository is unit-testabilityAnother advantage of abstracting the DbContext with a Repository is unit-testability. You can have your IRepository interface to which has 2 implementations, one (the real Repository) which uses DbContext to talk to the database and the second, FakeRepository which can return in-memory objects/mocked data. This makes your IRepository unit-testable, thus other parts of code which uses IRepository.

public interface IRepository
{
  IEnumerable<CustomerDto> GetCustomers();
}
public EFRepository : IRepository
{
  private YourDbContext db;
  private EFRepository()
  {
    db = new YourDbContext();
  }
  public IEnumerable<CustomerDto> GetCustomers()
  {
    return db.Customers.Select(f=>new CustomerDto { Id=f.Id, Name =f.Name}).ToList();
  }
}
public MockRepository : IRepository
{
  public IEnumerable<CustomerDto> GetCustomers()
  {
    // to do : return a mock list of Customers
    // Or you may even use a mocking framework like Moq
  }
}

Now using DI, you get the implementation

public class SomeService
{
  IRepository repo;
  public SomeService(IRepository repo)
  {
     this.repo = repo;
  }  
  public void SomeMethod()
  {
    //use this.repo as needed
  }    
}

I don't see any reason for the Repository pattern to not work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/XML/web service), it is good to have an abstraction layer. The Repository pattern works well in this scenario. I do not believe that Entity Framework is enough abstraction to hide what goes on behind the scenes.

I have used the Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the DbContext with a Repository is unit-testability. You can have your IRepository interface to which has 2 implementations, one (the real Repository) which uses DbContext to talk to the database and the second, FakeRepository which can return in-memory objects/mocked data. This makes your IRepository unit-testable, thus other parts of code which uses IRepository.

I don't see any reason for the Repository pattern to not work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/XML/web service), it is good to have an abstraction layer. The Repository pattern works well in this scenario. I do not believe that Entity Framework is enough abstraction to hide what goes on behind the scenes.

I have used the Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the DbContext with a Repository is unit-testability. You can have your IRepository interface to which has 2 implementations, one (the real Repository) which uses DbContext to talk to the database and the second, FakeRepository which can return in-memory objects/mocked data. This makes your IRepository unit-testable, thus other parts of code which uses IRepository.

public interface IRepository
{
  IEnumerable<CustomerDto> GetCustomers();
}
public EFRepository : IRepository
{
  private YourDbContext db;
  private EFRepository()
  {
    db = new YourDbContext();
  }
  public IEnumerable<CustomerDto> GetCustomers()
  {
    return db.Customers.Select(f=>new CustomerDto { Id=f.Id, Name =f.Name}).ToList();
  }
}
public MockRepository : IRepository
{
  public IEnumerable<CustomerDto> GetCustomers()
  {
    // to do : return a mock list of Customers
    // Or you may even use a mocking framework like Moq
  }
}

Now using DI, you get the implementation

public class SomeService
{
  IRepository repo;
  public SomeService(IRepository repo)
  {
     this.repo = repo;
  }  
  public void SomeMethod()
  {
    //use this.repo as needed
  }    
}

I don't see any reason for the Repository pattern to NOTnot work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/ XML XML/Webweb service), Itit is good to have an abstraction layer. The Repository pattern works well in this scenario. I do not believe that Entity frameworkFramework is enough abstractiveabstraction to hide what is goinggoes on behind the scenescenes.

I have used the Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the db contextDbContext with a Repository is unit testability,-testability. You can have your iRepositaryIRepository interface to which has 2 implentationimplementations, one (the real RepositaryRepository) which uses dbContextDbContext to talk to the database and the second, FakeRepositaryFakeRepository which can return in memory-memory objects/mocked data. This makes your IRepositaryIRepository unit testable-testable, thus other parts of code which uses IRepositaryIRepository.

I don't see any reason for Repository pattern to NOT work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/ XML /Web service), It is good to have an abstraction layer. Repository pattern works well in this scenario. I do not believe Entity framework is enough abstractive to hide what is going behind the scene.

I have used Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the db context with a Repository is unit testability, You can have your iRepositary interface to which has 2 implentation, one (the real Repositary) which uses dbContext to talk to the database and the second, FakeRepositary which can return in memory objects/mocked data. This makes your IRepositary unit testable, thus other parts of code which uses IRepositary

I don't see any reason for the Repository pattern to not work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/XML/web service), it is good to have an abstraction layer. The Repository pattern works well in this scenario. I do not believe that Entity Framework is enough abstraction to hide what goes on behind the scenes.

I have used the Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the DbContext with a Repository is unit-testability. You can have your IRepository interface to which has 2 implementations, one (the real Repository) which uses DbContext to talk to the database and the second, FakeRepository which can return in-memory objects/mocked data. This makes your IRepository unit-testable, thus other parts of code which uses IRepository.

added 408 characters in body
Source Link
Shyju
  • 1.5k
  • 1
  • 9
  • 6

I don't see any reason for Repository pattern to NOT work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/ XML /Web service), It is good to have an abstraction layer. Repository pattern works well in this scenario. I do not believe Entity framework is enough abstractive to hide what is going behind the scene.

I have used Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the db context with a Repository is unit testability, You can have your iRepositary interface to which has 2 implentation, one (the real Repositary) which uses dbContext to talk to the database and the second, FakeRepositary which can return in memory objects/mocked data. This makes your IRepositary unit testable, thus other parts of code which uses IRepositary

I don't see any reason for Repository pattern to NOT work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/ XML /Web service), It is good to have an abstraction layer. Repository pattern works well in this scenario. I do not believe Entity framework is enough abstractive to hide what is going behind the scene.

I have used Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

I don't see any reason for Repository pattern to NOT work with Entity Framework. Repository pattern is an abstraction layer you put on your data access layer. Your data access layer can be anything from pure ADO.NET stored procedures to Entity Framework or an XML file.

In large systems, where you have data coming from different sources (database/ XML /Web service), It is good to have an abstraction layer. Repository pattern works well in this scenario. I do not believe Entity framework is enough abstractive to hide what is going behind the scene.

I have used Repository pattern with Entity Framework as my data access layer method and am yet to face a problem.

Another advantage of abstracting the db context with a Repository is unit testability, You can have your iRepositary interface to which has 2 implentation, one (the real Repositary) which uses dbContext to talk to the database and the second, FakeRepositary which can return in memory objects/mocked data. This makes your IRepositary unit testable, thus other parts of code which uses IRepositary

added 5 characters in body
Source Link
gnat
  • 20.9k
  • 29
  • 115
  • 295
Loading
Post Migrated Here from stackoverflow.com (revisions)
Source Link
Shyju
  • 1.5k
  • 1
  • 9
  • 6
Loading