Sam King

Sam King

  • NA
  • 50
  • 11.1k

Understand repository functions

Jul 26 2017 1:57 AM
Hello Folks,
 
I am learning UnitofWork ,Repository pattern and in the genericrepository.cs file i have a method like this and i am not sure how to use that in real example.
 
 
/// <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);
}
 
for example if we have two repositories rep1,rep2 with a foreignkey relationship will this join two repositories and output it to a list
 
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;
}