g.pickardou
g.pickardou

Reputation: 35913

Can we call EF DbContext to UnitOfWork, and its Set<T> to Repository?

If yes, then we are done... no need to design and implement repos and unit of work when using EF (with DbContext)

Maybe I missed something, but for me DbContext implements a perfect UnitOfWork (well the interface is missing... :-( ) and its .Set are the generic repos for entity T.

Why then people keep implementing repos what are using/have a context, and implement unit of works what are using/have one of more repos? They implementing a design patter using an implementation of the same design pattern.

(I know: EF DbContext is not implementing a usable interface which fits to UnitOfWork/Repo pattern, but beside this, missed I something?)

Thx in advance

Upvotes: 0

Views: 169

Answers (2)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

Yes they are the implementation of unit of work and the repository pattern.
I think the only case where you need to use your own repositories or unit of work is when you are planing to separate your data access logic from the repository level . That means if you are going to use some another way of accessing database (like Nhibernate) later ,then it is easy to have your own repository layer.

And also if you need to have another type of datasources not only the entity framework, then it is better to have an abstraction layer for your data access like this.

Upvotes: 2

Oleksandr Kobylianskyi
Oleksandr Kobylianskyi

Reputation: 3380

You are right.

But people are implementing their custom versions on top of already existing if they miss some features (for example DbSet is too generic repository with lack possibilities for query reuse (for example with specification pattern)).

Upvotes: 0

Related Questions