EF/Repository/Unit of Work を使用していますが、詳細を理解するのに苦労しています。UnitOfWork 内で、新しい EF DbContext (EmmaContext) を作成しますが、リポジトリ内を見て、間違っているとわかっているものをキャストします。リポジトリ内のコンテキストを正しく取得するにはどうすればよいですか? たぶん私は完全に間違った道を進んでいますか?
ここに私の UnitOfWork があります:
//Interface
public interface IUnitOfWork : IDisposable
{
    void Commit();
}
//Implementation
public class UnitOfWork : IUnitOfWork
{
    #region Fields/Properties
    private bool isDisposed = false;
    public EmmaContext Context { get; set; }
    #endregion
    #region Constructor(s)
    public UnitOfWork()
    {
        this.Context = new EmmaContext();
    }
    #endregion
    #region Methods
    public void Commit()
    {
        this.Context.SaveChanges();
    }
    public void Dispose()
    {
        if (!isDisposed)
            Dispose(true);
        GC.SuppressFinalize(this);
    }
    private void Dispose(bool disposing)
    {
        isDisposed = true;
        if (disposing)
        {
            if (this.Context != null)
                this.Context.Dispose();
        }
    }
    #endregion
}
リポジトリは次のとおりです。
//Interface
public interface IRepository<TEntity> where TEntity : class
{
    IQueryable<TEntity> Query();
    void Add(TEntity entity);
    void Attach(TEntity entity);
    void Delete(TEntity entity);
    void Save(TEntity entity);
}
//Implementation
public abstract class RepositoryBase<TEntity> : IRepository<TEntity> where TEntity : class
{
    #region Fields/Properties
    protected EmmaContext context;
    protected DbSet<TEntity> dbSet;
    #endregion
    #region Constructor(s)
    public RepositoryBase(IUnitOfWork unitOfWork)
    {
        this.context = ((UnitOfWork)unitOfWork).Context;
        this.dbSet = context.Set<TEntity>();
    }
    #endregion
    #region Methods
    public void Add(TEntity entity)
    {
        dbSet.Add(entity);
    }
    public void Attach(TEntity entity)
    {
        dbSet.Attach(entity);
    }
    public void Delete(TEntity entity)
    {
        dbSet.Remove(entity);
    }
    public IQueryable<TEntity> Query()
    {
        return dbSet.AsQueryable();
    }
    public void Save(TEntity entity)
    {
        Attach(entity);
        context.MarkModified(entity);
    }
    #endregion
}