简体   繁体   中英

Change table name at runtime using Entity Framework 4

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?

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM