South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
If I understand you correctly, what you want to use is a MicroORM library (there are many around, have a look at http://www.toptensoftware.com/petapoco/)
I've written such a micro ORM lib, but can't share it, the opensource libs are way more feature rich anyways.
That is such a bloated way of doing things. He can write a 30 line class to give him what he needs. Or just use the expandoobject
Well he can weave his own reflection emit code, its not actually difficult at all instead of bringing in an entire orm.
I have my own ORM framework because I wrote it MANY moons ago. Before EF and it also runs on Compact Framework. It is very lightweight.
Right at the lowest level it uses my ReflectionRecordReader class. This class iterates through the DataReader fields for the current row and sets the object properties from the DB columns using reflection. This is where the performance hit comes. My ORM framework is such that I can inject any record reader into the data access layer but the default is the reflection based reader.
I have done some perf tests. To open the DataReader and iterate through all rows without actually reading the row field values take 150ms for 1000 rows. Using my ReflectionRecordReader, it takes 4500ms. Factor of 20 times slower. The table has 180 columns.
The system is currently running on .NET Framework 2 only...
So yes I can weave my own reflection emit code (as in the CodeProject article) but that is where i need the help....
Are you caching the data column offsets, or do you find the index of a column with each iteration ? (makes a big difference wrt performance).
I assume you're using vanilla Reflection to set the values of Fields and Properties.
- A possible quick win would be to only use Fields
- Alternatively, have a look at this link, it basically shows you how to generate getters and setters for properties (using emit as you requested)
http://jachman.wordpress.com/2006/08/22/2000-faster-using-dynamic-method-calls/
Good luck.
Ah okay, well i can put something together for you over the weekend.(Bit busy right now). If you can wait that long...
Awesome man, appreciated.
The DAL class is a generic class that you instantiate with the type of the object to retrieve.
It uses reflection to build the database metadata (column names etc) from the object type. So it ends up with a mapping between
DB column name and object property name. It builds all the SQL statements from there. The record reader then uses this as input to set the property names from the DataReader fields. So you would need this class. PM me your email then I will send it to you. Some of the class properties can be nullable as well. the types I mostly use in my objects are
string
DateTime
byte
short
int
long
float
decimal
double
and their Nullable<T> versions
Lemme know if you have Q's
Tx
Are you caching the data column offsets, or do you find the index of a column with each iteration ? (makes a big difference wrt performance).
I assume you're using vanilla Reflection to set the values of Fields and Properties.
- A possible quick win would be to only use Fields
- Alternatively, have a look at this link, it basically shows you how to generate getters and setters for properties (using emit as you requested)
http://jachman.wordpress.com/2006/08/22/2000-faster-using-dynamic-method-calls/
Good luck.
I'll write a generic builder and then you can adapt it where required.