Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After performing a Pivot in SQL I end up with a datasource with a few known columns and a variable amount of unknown (at design time) columns.

I used the classic DataSet - DataTable solution, but started hitting OutOfMemory exceptions while processing the data (60,000 rows and 95 columns).

I then realized I needed a lighter weight solution and so used Reflection.Emit to construct my types at runtime. This worked perfectly giving me a 10x performance increase over the DataTables, however, the processing code was quite complex, so for simplicity sake I changed the code to generate a type that inherits from a defined base type where the base type contains the known columns and I used Reflection.Emit to define a new type extending the base class and adding the extra columns at run time.

This simplified the code nicely and I can construct and fully populate these objects correctly.

The problem is that when I bind them to a DataGrid, only the base type's columns are visible. If I add a reference to the object in the debugger I can also only see the properties of the base class (Grid.DataSource(0)), however if I check the type I can see all the properties are there - Grid.DataSource(0).GetType.GetProperties().

Anyone know why the DataGrid and other data visualizers refuse to find these added properties?
Posted

1 solution

You have to give the approrpate flags to emit fields - e.g. http://msdn.microsoft.com/en-us/library/system.reflection.fieldattributes%28v=vs.110%29.aspx[^].
 
Share this answer
 
Comments
Brendon Webber 3-Feb-14 3:18am    
The backing field for my property has been defined with FieldAttributes.Private and the property has been defined with the Read and Write PropertyAttributes.

The Emit solution works when I do not inherit my generated class type from a defined base type, therefore I feel that my properties are defined correctly.

It would seem that there is an issue with extending defined types.

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