I have a List of BlogPageModel , in List I have string Array of Category.
Model class looks like below:
public class BlogPageModel : BaseModel
{
public string Title { get; set; }
public string Slug { get; set; }
public string[] Category { get; set; }
}
I want list of all Category with blogs count as output, i.e
Travel-20
Entertainment-5
Note: Travel-20 mean 20 blogs are in list which have Travel Category, and Entertainment-5 mean 5 blogs are Entertainment category, remember few blogs have both categories.
I tried to apply GroupBy like below:
_client.GetRecords().Result.GroupBy(x => x.Category).Select(x => new { Key = x.Key })
But it's not working and returning list of blogs.
I also tried below:
I am not sure what I am doing wrong in my query.

Travel-20mean that 20BlogPageModel's in your list have the string "Travel" in theCategoryarray?C#to test right now, but I think there is some sort ofCount()or similar method to put afterSelect()Categoryshould be calledCategories. Collections should have a plural name