开发者

DataContext, Repositories and Unit of Work

开发者 https://www.devze.com 2023-03-22 00:39 出处:网络
I have 2 repositories for 2 different entities and each one has its own private LINQ-to-SQL DataContext.

I have 2 repositories for 2 different entities and each one has its own private LINQ-to-SQL DataContext.

In 开发者_JS百科addition, I have a service class that must return a result from these 2 repositories.

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.)

Question 2 - Is that what the Unit of Work is for? Many thanks for the help.


This tutorial answered my questions:

http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

0

精彩评论

暂无评论...
验证码 换一张
取 消