本文介绍了DataContext,存储库和工作单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有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:
这篇关于DataContext,存储库和工作单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!