0

製品

ID カテゴリ ID 名前 ...

カテゴリー ID ParentCategoryID Name

製品 > CategoryID = 外部キー

public class NameIDCount
{
    public int ID {get;set;}
    public string Name { get;set;}
    public int Count { get;set;}
}

public class NameIDCountList
    {
        public NameIDCount _Category { get; set; }
        public List<NameIDCount> _SubCategories { get; set; }
    }

どうやって

Linq クエリ?

List<NameIDCountList> NameIDCountList =リンク?

結果:

<a href="/category/id=1">PC [23]</a>
    <a href="/category/id=4">NoteBook [2]</a>
    <a href="/category/id=5">Desktop [21]</a>
<a href="/category/id=2">Monitor [6]</a>
     <a href="/category/id=8">LED Monitor [4]</a>
     <a href="/category/id=9">LCD Monitor [2]</a>
4

1 に答える 1

0

このようなことを試してください

        var nameidlist = new List<NameIDCount>
        {
            new NameIDCount{ID=1,Name="PC", Count =1},
            new NameIDCount{ID=2,Name="PC", Count =1},
            new NameIDCount{ID=3,Name="PC", Count =1},
            new NameIDCount{ID=4,Name="Monitor", Count =1}
        };

        var nl = new List<NameIDCount>();

        nameidlist.GroupBy(x => x.Name, p => p.ID).ToList().ForEach((y) =>
        {
            nl.Add(new NameIDCount { Count = y.ToList().Count, Name = y.Key });
        });
于 2013-05-12T14:20:58.903 に答える