1

Some time back I started using EF as a DAL and from tutorials and videos come to know about repository pattern and Unit of work patterns.

About repository I learned it is an abstraction over DAL and it separate business logic from data access code. Also that it avoid reputation of data access code and help in unit testing.

I understand repository pattern is a particular way of making DAL. But what it brings ? I am not getting. My confusion is just making a DAL (a separate class library/ project) it will also give these benefits (separate data access logic from business logic, save data access code reputation, help in unit testing etc).

Probably I am still missing benefits of repository patren. Please guide me on this.

user576510
  • 5,777
  • 20
  • 81
  • 144
  • Check this answer http://stackoverflow.com/questions/5401957/repository-pattern-with-entity-framework/5402554#5402554 – Eranga Jul 14 '12 at 05:03
  • possible duplicate of [Repository Pattern vs DAL](http://stackoverflow.com/questions/291344/repository-pattern-vs-dal) – nawfal Feb 16 '13 at 07:57

1 Answers1

1

Data Access Layer is supposed to deal with data sources like databases, but to achieve some higher level goals as described by MSDN you need repository pattern.

As per MSDN

  • You want to maximize the amount of code that can be tested with automation and to isolate the data layer to support unit testing.
  • You access the data source from many locations and want to apply centrally managed, consistent access rules and logic.
  • You want to implement and centralize a caching strategy for the data source. You want to improve the code's maintainability and readability by separating business logic from data or service access logic.
  • You want to use business entities that are strongly typed so that you can identify problems at compile time instead of at run time.
  • You want to associate a behavior with the related data. For example, you want to calculate fields or enforce complex relationships or business rules between the data elements within an entity.
  • You want to apply a domain model to simplify complex business logic.
Asif Mushtaq
  • 13,010
  • 3
  • 33
  • 42
  • Asif in case of DAL (without repository), again I will have a just DAL classes where only I will be doing changes. I couldn't really get its benefit. – user576510 Jul 14 '12 at 04:54