Opinions on generating CLSA-derived types at runtime? (e.g. TypeBuilder)

Opinions on generating CLSA-derived types at runtime? (e.g. TypeBuilder)

Old forum URL: forums.lhotka.net/forums/t/7310.aspx


rsbaker0 posted on Tuesday, July 21, 2009

The particular use case is that our application allows end-users to extend the database schema with custom fields. These can either be validated from another table or not, in which case the user gets to define the values and their descriptions (very much like name-value lists in CSLA).

If this were the end of the story, I wouldn't be asking this, but now the user can also extend these validation tables with their own custom fields, which could also be validated, etc.

So, each such object has a "fixed" part (the key and description fields, and a variable part, other custom fields). As such, they all really implement the same behavior.

We already handle the variable part, but the DAL wants a 1-1 between class names and underlying table name. Also, the business rules vary depending on whether the custom fields are validated.

I've found I can generate the class I want with TypeBuilder without emitting any IL. I have a generic class for the base that does all the work, and so I just generate a class with the same name as a the table and derive it from the generic base.

All that would remain would be for me to register this class with the ORM, but before I explore this further I was wondering if I am unknowingly wading into a can of worms (trust issues, etc.)

Any advice welcomed...

 

JonM replied on Tuesday, July 21, 2009

I find this concept interesting. When you add custom fields are they also being added to you database schema on the fly? If so are you using sql server? And how do you deal with the unpredictable index performance problems that this would cause?

rsbaker0 replied on Tuesday, July 21, 2009

Yes, they are added to the schema on the fly. (Of course, the database user must have the appropriate privileges).

We support SQL Server, Oracle, and (hanging by a thread at this point) Access.

I'm not sure anyone has ever complained about index problems specifically related to the custom field support. My knowledge of this is limited to that if the user does a search of a large table on a custom field, then you'll get a table scan of the table unless it was explictly indexed, but then this is true of any non-indexed field. One of our customers runs on Oracle and has added over 200 fields to our schema, most with validation tables.

Copyright (c) Marimer LLC