CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Ben Reichelt's Weblog


Dynamically Mapping a Custom Entity



Comments

Jeremy D. Miller said:

That's fine as a cool thought exercise, but why swallow all that inefficiency when you could predefine the mappings with one of any number of O/R tools? This would also tightly couple the domain classes to the database structure.

The other big issue you'd hit doing this would be type coercion between the DB types and your entity properties.
# August 24, 2005 10:57 PM

breichelt said:

Jeremy, I realize that there are some perf issues as well, the intent of this was really just academic because Chris's post piqued my interest. However, I think that by caching the reflection part you could improve perf.

As far as having classes tied to the database structure I agree with you theoretically, but what this really means that is that the classes are tightly coupled to the capabilities of the sql language. I could define a view that combines tables and aggregates some information, and use that as the datasource that drives an object, rather than just a table.

You are absolutely right about the data type mismatch, can't deny that :-)
# August 24, 2005 11:21 PM

Jeremy D. Miller said:

You *could* beat the performance issue by emitting IL on the fly. Someone someday is going to write an O/R tool this way that'll blow away everything else in performance.

The only little problem I see is the order of magnitude increase in developer effort;)
# August 25, 2005 12:07 AM

J.R. said:

I didn't follow the reflection code too closely but we do some reflection on mapping data from a db into our value objects. There are things to consider such as performance. There was an article not too long back (wish I could find the url) but there are reflection methods that are faster than others. If you keep the reflection simple and don't go looking up dll's it's fairly quick. The one downside to how we are approaching is is the method we are using is in each data object class. That keeps the reflection faster.
# August 25, 2005 7:39 AM

Chris Wallace said:

While I don't necessarily think what we have explored so far is optimal, I do think it is these little explorations to see what we can do that inspire product changes or new products. Yes, you can dynamically gen the code up front with an OR tool but that leaves you (at least from I've seen) with the reader to object mapping code in every method (duplicated code). That duplicated code is what I was trying to see if we could avoid.
# August 25, 2005 7:51 AM

Nick Harrison said:

Here is a link to a blog where I discuss my findings in regards to performance of similiar custom entity mappings. One thing that I found was that a "reflective mapper" written well is faster than a "hard coded mapper" written badly. Since a reflective mapper has to be written well only once and a hard coded mapper could be written badly any time that it is reproduced. Odds are that the hard coded approach will be written badly atleast on occassion.

I have also seen good results with code generation. But there is no need for the code to be generated at run time. The mapping logic and the custom business entity object for that matter could be generated at design time. Generated code would be consistent, follow best practices, and potentially yield faster code than the other methods.
# September 28, 2005 12:37 AM

Nick Harrison said:

# September 28, 2005 12:38 AM

Nick Harrison said:

# September 28, 2005 12:39 AM
Check out Devlicio.us!

Our Sponsors

Proudly Partnered With