【发布时间】:2012-08-02 08:15:01
【问题描述】:
干杯!我对将工作单元与存储库一起使用有些疑问。特别是实体框架中的子上下文角色。 我搜索了很多关于这个主题的信息,但我发现的只是不同类型的使用模式,我很困惑,我无法理解主要思想。
1.我应该在哪里实现配置和保存? - DbContext 的 Inheritance 类中是否正确实现 Disposable? 之后在 Repository 和 Unit of Work 中实现还是仅在 Uni fo Work 中实现?
-将方法Save放在工作单元或存储库中的什么位置?
我的存储库将是通用的 我的代码在架构师风格和其他细节上是否正确?请指出我的想法是否错误。
interface IRepository : IDisposable
{
void Create();
void Delete();
void Update();
void Get();
T getSomeByExpression()
...Some another costum operations
...should I remember about Save here?
}
class Repository : IRepository
{
SomeContext context = new SomeContext();
...Using using(context = new SomeContext()){} in functions??
...
....Disposing?
}
interface IUnitOfWork : IDisposable
{
...Which methods I should realize?
Commit()
Save()
...Need some another methods like rollback, Attach() Add() or Dispose or something else?
}
class UnitOfWork
{
...Collection of Repository
}
在逻辑级别的工作单元之后使用? 请帮助我理解这个主题。
我想知道,如何正确使用 Unit Of Work 和 Repository 模式,尤其是包括 DBContext。我还想知道在哪里使用像 Dispose 这样的操作。 哪些操作应该在 UnitOfWork 中常见,Save 等。 如何在存储库中处理上下文?
【问题讨论】:
标签: c# entity-framework-4 repository dispose unit-of-work