I'm trying to group by CategoryId and display the CategoryId + the Name property of the group, I need help modifying this code so the Name property can be displayed, check out view below th see what I mean.
Database
ItemCategory
int ItemId
int CategoryId
Category
int CategoryId
int? ParentId
string Name
var itemcategories = db.Fetch<ItemCategory, Category>(@"SELECT * FROM ItemCategory LEFT JOIN Category on Category.CategoryId = ItemCategory.CategoryId WHERE ItemId = @0", item.ItemId);
var grouped = from b in itemcategories
where b.Category.ParentId != null
group b by b.Category.ParentId ?? 0 into g
select new Group<int, ItemCategory> { Key = g.Key, Values = g };
public class Group<K,T>
{
public K Key;
public IEnumerable<T> Values;
}
In view
@foreach (var group in @Model.ItemCategories)
{
@group.Key **Category.Name should be displayed here**
}
foreach (var value in group.Values)
{
@value.Category.Name
}