2

我有一个使用通用上下文的 UnitOfWork。如何让存储库决定使用结构映射的具体上下文?

  public SomeRepository(IUnitOfWork unitOfWorkSomeContext)
        {
        _uowContext = unitOfWork.Context as ISomeContext;

        }

public class UnitOfWork: IUnitOfWork
{
    private readonly IContext _context;

    public UnitOfWork(IContext context)
    {
        context.Configuration.AutoDetectChangesEnabled = false;
        context.Configuration.ProxyCreationEnabled = false;
        context.Configuration.LazyLoadingEnabled = false;
        _context = context;
    }
    public int Save()
    {
        return _context.SaveChanges();
    }

    public IContext Context
    {
        get { return _context; }
    }

    public void Dispose()
    {
        _context.Dispose();
    }
}

谢谢,

道格

4

0 回答 0