Change table name at runtime using Entity Framework 4

ε祈祈猫儿з 提交于 2019-12-11 23:23:38

问题


Is it possible to change the name of the table a specific entity is mapped to in Entity Framework 4 (model first)? I need to create one model per customer and thus need to prefix the table names. Maybe simpler to use one database per customer. What is the best practice?


回答1:


Use database per customer. Databases must have same schema. Modifying mapping at runtime is not a good idea.

Edit:

Model per customer means EDMX per customer. Be aware that metadata are shared. So in multi-tenant application (that is how I understand your description) every change to metadata will change metadata for every request. Also using separate database looks like better architecture in terms of security and performance.

Another question is if metadata can be changed at runtime. Metadata are stored in MetadataWorkspace. You can read them but I'm not sure if you can also modify them (I will check it during weekend).




回答2:


EF-generated model is generated based on your database schema. I don't see how you can alter the schema within EF. Does not compute in my little head.

With that said, you can perhaps write a stored procedure that alters the table, and call that stored proc via your EF context.



来源:https://stackoverflow.com/questions/5426963/change-table-name-at-runtime-using-entity-framework-4

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