Repository pattern with Linq to SQL using IoC, Dependency Injection, Unit of Work

老子叫甜甜 提交于 2019-12-03 01:36:57
Bryan Watts

Here is an answer of mine to a similar question.

The basic idea is that generic repository interfaces don't work so well, but generic repository implementations work great. It uses LINQ to SQL as the example ORM and should provide some insight to your question.

Be sure to read through Paul's answer as well, especially the comments.

Well this is a problem I've seen a lot of times. You want to have the decoupling of your business objects from your data storage strategy. As your doing a projection to your business objects you lose a lot of the nice features of having a repository (you could return IQueryable for example making use of deffered execution). The only way you can implement this is by giving your Repository a dependency towards an IMapper<BusinessObject> for example. This way you can map your business object to the object your repository needs in order to store something but leaving the abstraction in place as your business objects remain persistence ignorant.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!