DataContext,存储库和工作单元

编程入门 行业动态 更新时间:2024-10-27 16:29:23
本文介绍了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:

www.asp/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-应用程序

更多推荐

DataContext,存储库和工作单元

本文发布于:2023-11-06 22:20:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564830.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元   工作   DataContext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!