Building an extensible data model, EF 4
I have a question very similar to this, How do you build extensible data model, with regards to building an application using an extensible data model, except using EF 4.
My requirement is to be able to allow usersi of my application to extend the data model at runtime on the fly. We're currently underway with building the system and have made use of EF as the DAL layer, with POCO classes generated from the standard T4 template.
Taking this post by Ayende, http://ayende.com/blog/3498/multi-tenancy-extensible-data-model, as a concise summary of the options, we've taken the option of an xml column in a table allowing us to put pretty much开发者_如何转开发 anything in there with no need to recompile.
As I understand it, the extended table approach would be better, it seems to work quite nicely for dynamics CRM, however how/would it be possible whilst using EF 4 on the fly?
One possible solution to this kind of task is the EAV Pattern > http://en.wikipedia.org/wiki/Entity-attribute-value_model
One approach, I have used in the past is to create generic columns for example, int1, int2, ... intn, varchar1, varchar2, ..., varcharn etc. This has advantages and disadvantages. Its not clean from the DB perpective (some DBAs will be horrified). But with SQL Severs Sparse Columns support storage is not a issue. So you can have a really wide table. But you will need to store some meta data somewhere like, varchar1 -> Name, int1 -> Age etc.
Now you can write normal sql/ef queries, searching is easier, SSRS is straight forward (no xml parsing).
I too would like to know if there is a better solution.
You might want to look at XML Property Promotion as a way to speed up access to the properties you have defined in the XML.
精彩评论