D
D
Dmitry2016-03-06 20:32:44
ASP.NET
Dmitry, 2016-03-06 20:32:44

How to use the Repository and UnitOfWork pattern?

Guys, tell me, do I understand the repository pattern correctly - does the repository contain all the logic of working as an entity from the database? Can Repository be used separately from UnitOfWork? If we use Repository + UnitOfWork, should the Repository contain the logic of CRUD operations, or should UnitOfWork do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BaranovskiyNE, 2016-03-10
@BaranovskiyNE

Yes, the repository hides the logic for fetching data from the database, providing methods like GetActiveAccounts, GetAccountByID, etc. For me, it can be used separately, but if you are modifying the data of various entities and it must occur within a single transaction, then you can’t get away from UnitOfWork. Regarding CRUD operations, it turns out that the repository performs data manipulations, and UnitOfWork makes sure that it all goes through a single transaction.

I
Ilya Trifonov, 2016-03-30
@ilyatrifonov

Keep an excellent online tutorial on ASP.NET MVC 5 . There are topics that are not included in this course, but they are useful to know and they are in the ASP.NET MVC 4 course . And specifically on your question - here is the chapter .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question