1

I have been using Symfony2 with Doctrine2 for some years. I have recently started using Microsoft's Entity Framework with MVC5. From my Symfony2 experience I understand that a repository's job is only to retrieve and return objects, no additional operations like Saving. Now every examples I have seen for EF has a method Save/Update as part of the repository.

For symfony I have been creating manager classes as follows:

interface IManager
{
    function getClassName() ;
    IRepository getRepository() ;
    function Save(object);
    function Update();
}

So I pass around the manager, if I need to retrieve objects I call the repository directly. If I need to save I call the manager's save method.

Is a repository supposed to support save/update? What do you think of my IManager class, should I also use it for EF?

d0001
  • 111

2 Answers2

1

Entity Framework is not the implementation of Repository Pattern. EF is the Object Relational Mapper. Yes, it looks and behaves like Repository Pattern with Save/Update functionality.

Your IManager makes sense, and with enough abstraction, the Manager doesn't have to be coupled to EF at all. That will give you an option of switching ORMs if needed.

Roman Mik
  • 141
1

I think what confuses you about EF is the database context. It allows you to query objects like a Repository and save changes in persistence like a Unit of Work.

You have a lot of work done with EF database context. All you have to do is segregate the responsibilities by creating specific repositories and a unit of work that share the database context and pesists all changes in presistence with a single save call.

Check this link about create Repositories and UoW in EF. It is clear and easy to understand.

jlvaquero
  • 161