0

I am working on a MVC3 code first web application and after I showed the first version to my bosses, they suggested they will need a 'spare' (spare like in something that's not yet defined and we will use it just in case we will need it) attribute in the Employee model.

My intention is to find a way to give them the ability to add as many attributes to the models as they will need. Obviously I don't want them to get their hands on the code and modify it, then deploy it again (I know I didn't mention about the database, that will be another problem). I want a solution that has the ability to add new attributes 'on the fly'.

Do any of you had similar requests and if you had what solution did you find/implement?

1 Answers1

0

I haven't had such a request, but I can imagine a way to get what you want. I assume you use the Entity Framework, because of your tag.

Let's say we have a class Employee that we want to be extendable. We can give this class a dictionary of strings where the key-type is string, too. Then you can easily add more properties to every employee.

For saving this structure to the database you would need two tables. One that holds the employees and one that holds the properties. Where the properties-table has a foreign-key targeting the employee-table.

Or as suggested in this Q&A (EF Code First - Map Dictionary or custom type as an nvarchar): you can save the contents of the dictionary as XML in one column of the employee table.

This is only one suggestion and it would be nice to know how you solved this.

Community
  • 1
  • 1
chrisgl
  • 44
  • 2
  • Thank you for the idea, I'll check it out and get back to you if I still have any questions, cheers –  Apr 04 '12 at 07:25
  • I like the concept you provided, and it makes sense! I'm still working on the implementation –  Apr 04 '12 at 13:59