相关疑难解决方法(0)

使用ServiceStack.ORMLite实现工作单元和存储库模式的最佳实践

假设有两个存储库接口:

interface IFooRepository
{
    void Delete(int id);
}

interface IBarRepository
{
    void Delete(int id);
}
Run Code Online (Sandbox Code Playgroud)

和IUnitOfWork接口类似:

interface IUnitOfWork : IDisposable
{
    void Commit();
    void Rollback();
}
Run Code Online (Sandbox Code Playgroud)

使用ServiceStack.ORMLite实现这些接口的最佳实践是什么,以便用户可以像使用它们一样使用它们

MyFooRepository.Delete(4);
// if an Exception throws here, Bar won't be deleted
MyBarRepository.Delete(7);
Run Code Online (Sandbox Code Playgroud)

要么

using (var uow = CreateUnitOfWork())
{
    MyFooRepository.Delete(4);
    MyBarRepository.Delete(7);
    uow.Commit();  //now they are in an transaction
}
Run Code Online (Sandbox Code Playgroud)

repository-pattern servicestack ormlite-servicestack

11
推荐指数
1
解决办法
4916
查看次数