To Use Repositories Or NOT

I have been using NHibernate for a while now and am happy writing test cases / mocks for Repository implementations such that my code never need hit a database. I have also used Entity Framework in the past and have a soft spot for it, and recently came across a post by the Entity Framework team saying that EF v6 is actually very testable and we can/could use it directly in our codebase.

Naturally I wanted to try this out, so I tried it out using EF6 using Repositories and directly and was pleasantly surprised with the results which I have documented in this article:

http://www.codeproject.com/Articles/875165/To-Repository-Or-NOT

Hope that helps someone out. Enjoy

Advertisements

4 thoughts on “To Use Repositories Or NOT

  1. Tudor Turcu says:

    Entity Framework (and most other O/RMs) already implement the repository design pattern..
    DbContext _is_ a repository.

    • sachabarber says:

      No I don’t agree, DbContext and most other ORMs are a UnitOfWork.

      I do agree they can do Repository type things too, but the reason for the Repository pattern (in my opinion) is to be able to abstract the ORM away

      • Tudor says:

        I think that the purpose of the repository pattern is to ‘mediate between the domain and data mapping layers using a collection-like interface for accessing domain objects’
        ( http://martinfowler.com/eaaCatalog/repository.html )
        ————–
        ‘A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection.’ – DbSets

        ‘Client objects construct query specifications declaratively…’ – IQueryable

        ‘..and submit them to Repository for satisfaction’
        —————-

        Indeed, the fact that EF since recently was not easy to mock, and adding a repository on top of it helps with this, that’s another story..

      • sachabarber says:

        Now that I do agree with, we are basically agreeing here I feel so yeah all good stuff

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: