For Organization Units, we used the code below to get entities in an Organization Unit including its child Organization Units. Is it reasonable and how to extend the IRepository to add this feature to all entities?
public virtual List<Product> GetProductsInOuIncludingChildren(long organizationUnitId)
{
var code = _organizationUnitRepository.Get(organizationUnitId).Code;
var query =
from product in _productRepository.GetAll()
join organizationUnit in _organizationUnitRepository.GetAll() on product.OrganizationUnitId equals organizationUnit.Id
where organizationUnit.Code.StartsWith(code)
select product;
return query.ToList();
}
First, inherit
IMustHaveOrganizationUnit:Then define the extension method:
Usage: