我有2个用于2个不同实体的存储库,每个存储库都有自己的专用LINQ-to-SQL DataContext.
I have 2 repositories for 2 different entities and each one has its own private LINQ-to-SQL DataContext.
此外,我有一个服务类,必须从这两个存储库返回结果.
In addition, I have a service class that must return a result from these 2 repositories.
问题1-两个存储库都应该有一个公共的DataContext吗? (我猜想是通过在服务类中实例化一个DataContext并将其注入到2个存储库中来的.)
Question 1 - Should I have a common DataContext for both repositories? (I guess by instantiating a DataContext in the service class and injecting it to the 2 repositories.)
问题2-这是工作单位的目的吗?非常感谢您的帮助.
Question 2 - Is that what the Unit of Work is for? Many thanks for the help.
推荐答案本教程回答了我的问题:
This tutorial answered my questions:
www.asp/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-应用程序
更多推荐
DataContext,存储库和工作单元
发布评论