Click here to Skip to main content
16,019,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Am working on treeview with counts.
Based on my search input am returing entity which having child entities, so need count of records in the entity.
for example Main entity is "Tree" under tree i have mango tree and Orang tree, so am looking like get counts of all my child entites count my tree should be

Main Entity
|---Tree (400)
........|------MangoEntity (150)
........|------OrangeEntity(250)
Posted
Comments
Maciej Los 16-Nov-15 11:58am    
What have you tried?

1 solution

This should just be a simple count:



C#
var myEnumerable = [new {id=1,arr=[1,2,3,4]},new {2,[1,2,3]},new {3,[1,2,3,4,5,6]}];

var countedFlat = myEnumerable.Select(a=>new {a.id,count = a.arr.Count()});

foreach(var anon in countedFlat)
{
  Console.WriteLine("id:{0} - count:{1}",anon.id,anon.count);
}


output
id:1 - count:4
id:2 - count:3
id:3 - count:6
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900