views:

1320

answers:

4

I want to use the entity framework. However I also have the requirement of allowing my users to define custom fields in our system. I would like to still use the entity framework and not use a a partial class with a hash table property.

Below is the solution I was thinking of, however it is not simple so I would like to see if there is a better way.

My idea currently, is to have a ModelManager object that would create a column on the appropriate table, modify the EDM files, and compile the files using the edmgen.exe. This would all have to happen in a different process and/or appdomain than the application, since the application would reference the resulting assembly. When the application restarts it will have access to the newly added field.

Is this the only way to do this with the Entity Framework? Thanks for your time.

A: 

You are going to end up spending more time trying to make this solution work then to get your entire project done using HashTables. I don't really think the entity framework is appropriate for this situation because,

  1. your code wouldn't be programmed to use the new fields that were generated
  2. you are going to have to deal with unloading the current assembly from the app domain, and reloading the new one
  3. you are really setting your self up for failure

Sorry but there are just some problems that are not easily applied to certain frameworks.

Nick Berardi
I appreciate your answer. I know this is difficult, but I want to stick with using the Entity Framework. The solution I have stated does work as I have tested it. I have edited the question to reflect this. I want to find out if there is another way to have this functionality in the Entity Framework
CoderGuy
+1  A: 

After reading some blog entries by the Entity Framework team and Julie Lerman, it sounds like they are looking at making this easier for the next version. Which means as far as I can tell, the way I stated in the question is the best way to dynamically add fields to the entity framework.

CoderGuy
A: 

Can you please send me the code related to this? so that i can explain u in a better way.

A: 

I'm just throwing this out there...

You could use extension methods and/or a partial class to let objects accept a dictionary of key/value pairs for custom field data. Then after the save event, you could insert/update that data using straight SQL.

SkippyFire