Group join in linq but only where childs is present -
i have simple query , want have list of categories , each category number of products inside.
from category in categories bring together product in products on category.id equals product.category_id productspercategories select new categories { category = category, products = productspercategories.count() }; but if there no products, don't want category appear. current construct, there categories no products inside. how can accomplish that?
just add together status
where productspercategories.any() or
where productspercategories.count() > 0 so query be:
from category in categories bring together product in products on category.id equals product.category_id productspercategories productspercategories.any() select new categories { category = category, products = productspercategories.count() }; linq
No comments:
Post a Comment