Last post Mar 21, 2013 04:43 PM by srigowri
Mar 20, 2013 11:46 AM|kralfy|LINK
I'm developing a little project using EF to interact with database. As I learned, it is very helpful to use a Repository pattern to provide specific access to entities (for example, a repository for Products entity will contain CheckAvailability method,
which will check if specified product is available, and so on). Also Repository pattern helps to wrap changes into transactions with the help of Unit of Work pattern.
But EF5 dbContext class already implements Repository and UoW patterns. Also, I don't find very comfortable to have about 10 repository classes for each of the entities in my model.
Instead, I can use the fact that DbContext is declared as partial, and I can add methods similar to methods in Repositories. As for me, this approach is much more comfortable - I have one class which provides convinient data access, and all benefits of UoW
pattern are saved.
You can say, that this approach doesn't provide the ability to unit test it. Yes, but unit testing is not needed here for me, I use integration testing with ready data, so the problem of testing is solved from the start.
My question is - what do you think about this approach? Maybe you can show me my mistakes here, or you can share your own ideas.
Thanks a lot!
Mar 21, 2013 04:22 PM|kralfy|LINK
OK, I'm done with this =)
Finally got full understanding of this problem =)
Mar 21, 2013 04:43 PM|srigowri|LINK
Instead of making dbcontext class as partial , you can have one generic repository interface and one generic repository class which implements generic repository interface for all the entities , with this we can implement UoW pattern and unit testing can
also be taken care.