Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Is Reflection good for object to db persistence?

I would like to define a parent class and then just call "Store" to save/load the object in a table. To reduce the amount of code and make it general, is it possible to inspect the child class and find out the data members names and values? Or is this a stupid idea?

Nordic Light
Tuesday, January 21, 2003

No, it's not a stupid idea - it's one of the reasons that reflection is in the system in the first place.

Chris Tavares
Tuesday, January 21, 2003

Custom attributes might be useful, too, rather than just reflection...

Big B
Tuesday, January 21, 2003

There are several java frameworks that make use of this technique. Check out and for some examples. I imagine the concepts would be just as applicable to a .NET solution.

In my experience, they are very convienient. However, you lose some peformance from using all the reflection. I have had success with starting my app with the reflection-based system, then refactoring in a hard-coded ORM when my schema is solid.

Matthew Christensen
Wednesday, January 22, 2003

*  Recent Topics

*  Fog Creek Home