因为 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 的应用程序,并且在阅读了很多关于具有单元可测试性的数据访问技术之后,我对上面的信息有点迷茫了!
最佳答案
这取决于项目的复杂程度及其要求。例如,这两个问题可能有助于您做出决策:
- 除了 EF 之外,您是否会使用任何其他必须与之配合使用的数据源?
- 您将来将 EF 换成不同的 ORM 或数据源的可能性有多大?
如果您无法预见变化,或者您不需要使用除 EF 之外的其他工具,那么这可能不值得麻烦。
关于c# - 我应该为 EF6 实现存储库和工作单元吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722490/