Last post May 23, 2017 09:35 AM by kashifdotnet
May 19, 2017 11:30 AM|kashifdotnet|LINK
Can someone point to a good working example of MVC5 with
EF6 using Repository Pattern & Unit of Work.
Being new to RP and UoW, I have googled many times but out of frustration, have yet to come across an example where the author shows how to use
1-to-M or M-to-M relationships.
Almost all the examples use a single Product or Course repository which doesn't depict a real-life example. Further, most of the debates are centered around using or not using the Repository Patterns with EF. In my opinion,
this should be left for the developers to decide.
All I want is a decent EF6 and MV5 example with RP and UoW (with DI and IoC)
using 1-to-M and M-to-M relationship. I would really appreciate some good links in this regards.
I really seek opinion of experts in this regard. Thanks in advance.
May 19, 2017 01:35 PM|Mikesdotnetting|LINK
Managing 1 to many or many to many relationships with EF 6 is not dependent on the repository pattern or the Unit of Work pattern. They are completely unrelated to each other. What I recommend is that you focus on is the simple examples showing just the
EF code for managing these scenarios. How you wrap that in repository methods is entirely up to you. You will find the Contoso examples adequate for this:
May 19, 2017 03:08 PM|kashifdotnet|LINK
Mke, your point is well taken. I have already developed applications using MVC5 with EF6 and understanding the working well.
My question stems from the requirements of SoC. For medium to large enterprise applications, mixing data logic in MVC Controllers becomes
nightmare hard to manage . For the reason of SoC, maintainability and testing, I am investing time into Repository Pattern and UoW.
Yes I agree that implementation is up to me, yet it's so difficult to find a good implementation (and I am not alone as many developers struggle to grasp this idea). And when I search the web, people are mainly debating about using or not using RP since
EF itself uses RP and UoW.
Again, if you can point to an implementation, that will be great.
Thanks again :-
May 19, 2017 07:35 PM|Mikesdotnetting|LINK
Have a look at the source code for nopCommerce: http://www.nopcommerce.com/downloads.aspx (second link)
May 21, 2017 06:23 PM|kashifdotnet|LINK
Mike, thanks for the reply again. I looked at the code and it looks pretty interesting. Please bear with me further.
nopCommerce and many other projects make use of Service classes. As far as I understand, these classes cater for specific functions such as a Coupon Service during a Transaction. Further, these are simple classes which provide a set of functions related
to an entity. Did I get it right?
May 22, 2017 08:54 AM|Mikesdotnetting|LINK
Further, these are simple classes which provide a set of functions related to an entity. Did I get it right?
May 23, 2017 09:35 AM|kashifdotnet|LINK
Mike, thanks again. This discussion is really helpful.
Taking the Services discussion further, if I architect my application such that the Rep & UoW are used for basic CRUD operations while Service Classes are used for specialized features (such as Shopping Cart), does this make a good architecture. Without
being a purist, the only issue I see is Service classes using the DbContext directly. Is this a violation of SoC?