Extending Entity Framework Model at application runtime

懵懂的女人 提交于 2021-01-29 00:40:55

问题


For a business application, I am providing a base entity model. Thereafter the end user should be able to extend the model for his specific needs.

For the base model I want to use database-first approach. But I don't know how to accommodate for allowing user to extend it.

One part is to provide a UI for entity model editing and the other is to reflect the changes in the model and database thereafter. Please offer suggestions.

EDIT:
- Once the entity model is edited and saved, all EF facilities should work like before.
- Model update is conducted at the time of maintenance, i.e., it is not in use by business users.
- The affected project can be compiled and a new assembly can be produced and put to use.


回答1:


It is not possible. When you modify entity model you must modify related entity classes (or create new ones) => you must recompile application or use some dynamic assemblies. Moreover there is no API to modify entity mapping at runtime so you are going to build new Entity designer.

It is generally same requirement as installing C# 2010 Express on client desktops and allowing them to modify, rebuild and redeploy your application.

Edit:

What you want requires:

  • Modifing EDMX - very complex XML file. Writing custom tool for that will be complex task. Moreover you will have to add logic wich will don't allow user to break the application.
  • Running T4 templates to generate new or modified entities.
  • Compiling application - what if user makes changes which break the build???
  • Redeploying DB - this itself is pretty bad taks because whole DB generation logic is Workflow running in Visual studio. Moreover you need another workflow which will be able to upgrade database - default one can only deploy new blank DB. Such workflow exists but it requires VS 2010 Premium or Ultimate.


来源:https://stackoverflow.com/questions/5181000/extending-entity-framework-model-at-application-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!