2017-02-10 6 views
0
public interface IRepository<TEntity, in TID> where TEntity : IAggregateRoot 
{ 
    TEntity Find(TID id); 
} 

そのimplimentationは、上記のリポジトリにTIDを渡す方法汎用リポジトリでEntityとIDを渡すには?

public class Repository<TEntity, TID> : IRepository<TEntity, TID> where TEntity : class, IAggregateRoot 
{ 
    public virtual TEntity Find(TID id) 
    { 
     return _unitOfWork.Session.Get<TEntity>(id); 
    } 
} 

の下に与えられていますか?

答えて

0

これは一般的なタイプです。インスタンスをリポジトリとして定義する必要があります。サンプルの場合、がであるProductというエンティティの場合。

var productRepository = new Repository<Product, int>(); 

// to call a method, you have to pass the TID defined, which is an int 
// and it will return a TEntity, that is a Product. 
Product product = productRepository.Find(1); 
関連する問題