I'm using EntityFrameowrk 4 and WinForms. I have a DataGridView which shows 5 to 12 thousands of records. The records are from different levels of hierarchy. There are records of classes A, B, C, D, where A contains a collection of B, B contains a collection of C, etc. The most numerous class is D. In the DataGridView this hierarchy is flattened and each record is shown in the row with some color/font formatting. To do this type of rendering I wrote the following code:
foreach (a in A)
{
var displayObjectA = new DisplayObject()
{
Name = a.Name,
Code = "Section",
Object = a
}
data.Add(displayObjectA);
var B = a.B;
foreach (b in B)
{
var displayObjectB = new DisplayObject()
{
Name = b.Name,
Code = "Subsection",
Object = b
}
data.Add(displayObjectB);
var C = b.C;
foreach (c in C)
{
var displayObjectC = new DisplayObject()
{
Name = c.Name,
Code = "Group",
Object = c
}
data.Add(displayObjectC);
var D = c.D;
foreach (d in D)
{
var displayObjectD = new DisplayObject()
{
Name = d.Name,
Code = d.Code,
Object = d
}
data.Add(displayObjectD);
}
}
}
}
after that the data is dispayed in the DataGridView. The problem is that this rendering is taking too long. And the most time consuming part seems to be the line
foreach (d in D)
in particular the call to a function
System.Data.Objects.DataClasses.EntityCollection<T>.GetEnumerator().
When I looked at this function in Reflector it shows that it's body is empty.
My questions are:
- Is there a better way to do this type of rendering?
- How do I increase the performance?
- Why is the GetEnumerator() empty? Is it constructed at run-time?