Last post Oct 10, 2012 01:09 PM by outhowz42
Oct 08, 2012 02:00 PM|outhowz42|LINK
I came across Project Silk a while ago and modeled a project after it using the repository pattern and conventions in that project. There is a data layer, business layer, and web layer. The business
layer contains all of the services that map the data entities to the domain model entities for use in the web layer. However, as my project has grown this "mapping" has gotten out of control.
Is there even a need to use the repository pattern anymore with EF? I can use my view models and good practices to ensure data integrity and prevent the user from updating anything in the DB that I don't want them to.
Have a look here to see the mapping I'm specifically talking about. ToDataModelUser() and ToServicesModelUser()
are the two methods I have that are giving me trouble.
In my project, I have a user, roles, departments, and appointments. As the relationships become more complex and tables are added, my ToDataModelUser() and ToServicesModelUser() have become quite cumbersome. User has a M2M relationship with roles, user also
has M2M relationship with departments, etc. When I try to map things, I eventually run into stack overflow errors.
Should I consider stripping this mapping out entirely and work directly with the entities from the DB? Thanks for any suggestions.
Oct 08, 2012 09:35 PM|DarrellNorton|LINK
The repository pattern does not require the mapping you are referring to, and I haven't looked at Silk in depth to see why they are doing that.
First off, if you have lots of mapping code, don't write it yourself. Use
Second, the repository pattern with EF is not really necessary. IDbSet is an implementation of the repository pattern. So you are adding another layer of abstraction (a repository on top of a repository/unit of work mix!). As long as you realize that, and
you need it (say to abstract yourself from EF in case you ever want to switch ORMs), then great. If not, it's needless abstraction. Another reason some use a repository, typically with generic types, is it makes code more testable. If that is your goal, do
a search on "unit testing EF 4 or 5" and see if you find a different approach that meets your needs.
Oct 10, 2012 01:09 PM|outhowz42|LINK
I don't anticipate changing the ORM ever and thus removed the mapping. I posted the question in a few forums and got similar answers in all of them. The removal of the unnecessary additional layer of abstraction and mapping improved performance on the site
and has made all new tasks much easier to implement. Thanks.