小编Tuf*_*ong的帖子

使用实体框架使用存储库和单元工作模式正确处置?

干杯!我对使用工作单元和存储库有些怀疑.特别是来自Entity Framework的子上下文的角色.我已经搜索了很多关于这个主题的信息,但是我发现只是不同类型的使用模式,我很困惑,我无法理解主要思考.

1.我应该在哪里实现处置和储蓄? - 它是否在DbContext的继承类中正确实现了Disposable?之后在存储库和工作单元中实现或仅在Uni fo工作中实现?

- 把方法保存在工作单元或存储库中?

我的存储库将是Generic我的代码在架构师风格和其他细节方面是否正确?请告诉我的想法是否错误.

    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? …
Run Code Online (Sandbox Code Playgroud)

c# dispose repository unit-of-work entity-framework-4

10
推荐指数
1
解决办法
2万
查看次数