Use generic include function in ASP.NET Core

asp.net c# entity-framework entity-framework-core generic-programming

Question

I have this generic include in ASP.NET Core:

 public IQueryable<T> AllIncluding(params Expression<Func<T, object>>[] includeProperties)
 {
     IQueryable<T> query = _uow.Set<T>();

     return includeProperties.Aggregate(query, (current, includeProperty) => current.Include(includeProperty));
 }

I have two tables:

public class Brand
{
    public int BrandId { get; set; }
    public string BFaName { get; set; }
    public string BEnName { get; set; }
    public int CatId { get; set; }
    public virtual ICollection<Category> Categories { get; set; }
    public virtual ICollection<ProductBrand> ProductBrands { get; set; }
}

public class ProductBrand
{
    public int Id { get; set; }
    public virtual Brand Brand { get; set; }
    public virtual Product Product { get; set; }
}

I need to find BrandId from Brand table by ProductID in Product.

How can I use this generic include to find the BrandID? What should I pass to this generic include?

0
1
2/3/2019 4:21:26 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow