0
私はUnitofWork、リポジトリパターンを学習しています。ジェネリックリポジトリファイルには、このようなメソッドがあります。実際の例でそのメソッドを使用する方法がわかりません。我々は、この2つのリポジトリと、リストに出力し、それに参加するForeignKeyの関係にある2つのリポジトリのREP1、REP2を持っている場合、例えば2つのリポジトリパターンをgetwithincludeメソッドに結合する
/// <summary>
/// Include multiple
/// </summary>
/// <param name="predicate"></param>
/// <param name="include"></param>
/// <returns></returns>
public IQueryable<TEntity> GetWithInclude(System.Linq.Expressions.Expression<Func<TEntity,
bool>> predicate, params string[] include)
{
IQueryable<TEntity> query = this.DbSet;
query = include.Aggregate(query, (current, inc) => current.Include(inc));
return query.Where(predicate);
}
は、私は、単一のリポジトリからの詳細を取得する方法を知っています。
public IEnumerable<CREntity> GetAllCR()
{
var mapper = CreateMapper();
var CRAll = _unitOfWork.Rep1.GetAll().ToList();
//var joinFD = _unitOfWork.Rep1.GetWithInclude(); ---how to add Rep2 using getwithinclude
if (CRAll.Any())
{
var CRModel = mapper.Map<List<ChangeRequest>, List<CREntity>>(CRAll);
return CRModel;
}
return null;
}
が見えます、ChildEntity2); ' – DavidG
回答ありがとうございます.1つの説明は、childentity1とchildentity2とは何ですか?彼らはエンティティクラスの名前Rep1とRep2またはFKの名前ですか? –
'Include'はリポジトリ名ではなくクラス' CREntity'のナビゲーションプロパティ名を含んでいなければなりません。 –