0
リポジトリパターンと作業単位を使用してMVCプロジェクトを試しています。リポジトリからIRepository UOWリポジトリパターンに変換できません
次は私のInitOfWorkから
public interface IUnitOfWork
{
IRepository<User> UserRepository { get; }
void Save();
}
であり、これはUnitOfWorkの中に次の行が「エラーが発生したUnitOfWork
public class UnitOfWork:IUnitOfWork, IDisposable
{
private JNContext context = new JNContext();
private bool disposed = false;
private IRepository<User> userRepository;
public IRepository<User> UserRepository
{
get
{
if (this.userRepository == null)
{
this.userRepository = new Repository<User>(this.context);
}
return this.userRepository;
}
}
public void Save()
{
this.context.SaveChanges();
}}
からである暗黙のうちにリポジトリからIRepository
にthis.userRepository = new Repository<User>(this.context);
を変換できません。
私は何が欠けています。私は答えを見つけることができず、私は一日中立ち往生しています。
あなたはリポジトリがIRepositoryを実装していることを、確信していますか? – wheeler
@wheeler:いいえ、そうではありませんでした。私は**公開クラスリポジトリを持っていたところで、TEntity:クラス**。 ** IRepository **を実装する必要がありますか? –
はい、IRepositoryを実装する必要があります。リポジトリにある。コンパイラはこれがなければそれを理解することはできません。 – RedgoodBreaker