에 합류 제품 테이블을 통해 제품을 계산하지만, 일부 인터넷 검색이 쿼리를 생성하는 저를 주도하고있다 엔티티 모델의 항목 및 각 카테고리의 모든 제품 수입니다.C#을 질의 범주 내가 방법이 떨어져있을 수 있습니다
나는 (카테고리 개체의 목록에있는 항목 등) 결과의 유형을 필요
Id = 6 (from ProductCategory)
ParentId = 4 (from ProductCategory)
Title = "Example" (from ProductCategory)
SortOrder = 2 (from ProductCategory)
NumOfProductsInThisCategory = 7 (count products from ProductsInCategories)
이 내 모델입니다 :
뷰 모델 :
public class ViewModelProductCategory
{
public int Id { get; set; }
public int? ParentId { get; set; }
public string Title { get; set; }
public int SortOrder { get; set; }
public int NumOfProductsInThisCategory { get; set; }
}
엔티티 모델 :
public class ProductCategory
{
public int Id { get; set; }
public int? ParentId { get; set; }
public string Title { get; set; }
public int SortOrder { get; set; }
}
public class ProductInCategory
{
public int Id { get; set; }
public int ProductId { get; set; }
public int ProductCategoryId { get; set; }
public int SortOrder { get; set; }
}
가능한 복제 [GROUPBY와 LINQ 및 계산 (https : //로 유래 .com/questions/7285714/linq-with-groupby-and-count) –
'x.Count()'와 같이두면 어떻게됩니까? [Fiddle] (https://dotnetfiddle.net/#)을 만들 수 있습니까? –