c# - 我应该为 EF6 实现存储库和工作单元吗?

标签 c# asp.net-mvc entity-framework unit-testing

因为 MSDN 说 DbContext :

A DbContext instance represents a combination of the Unit Of Work and Repository patterns such that it can be used to query from a database and group together changes that will then be written back to the store as a unit. DbContext is conceptually similar to ObjectContext.

使用 EF5+ 实现这两个(Unit of Work & Repository)不是多余的吗?

有人可以进一步阐明这个主题吗?

我打算使用 SQL Server 构建一个基于 MVC 的应用程序,并且在阅读了很多关于具有单元可测试性的数据访问技术之后,我对上面的信息有点迷茫了!

最佳答案

这取决于项目的复杂程度及其要求。例如,这两个问题可能有助于您做出决策:

  1. 除了 EF 之外,您是否会使用任何其他必须与之配合使用的数据源?
  2. 您将来将 EF 换成不同的 ORM 或数据源的可能性有多大?

如果您无法预见变化,或者您不需要使用除 EF 之外的其他工具,那么这可能不值得麻烦。

关于c# - 我应该为 EF6 实现存储库和工作单元吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722490/

相关文章:

c# - 需要帮助转换

c# - 无法发现 NUnit 测试用例

c# - return myVar 与 return (myVar) 之间有区别吗?

c# - 在 Outlook 2010 的加载项中,如何使删除操作可撤消?

c# - 模型中的 Rotativa PDF - ControllerContext

asp.net-mvc - MvcBuildViews true 导致 "'/temp' is not a valid IIS application"错误

c# - Html.Grid 中的复选框值

entity-framework - 如何使用 Azure 存储和 Entity Framework 上传文件

c# - Entity Framework 核心代码优先 : Cascade delete on a many-to-many relationship

c# - Linq Time(7) 和 TimeSpan 映射