使用实体框架4在运行时更改表名 [英] Change table name at runtime using Entity Framework 4

查看:153
本文介绍了使用实体框架4在运行时更改表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在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.

编辑:

模型每个客户的意思是每个客户的EDMX。请注意,元数据是共享的。因此,在多租户应用程序(即我如何理解您的描述)中,元数据的每个更改将会更改每个请求的元数据。在安全性和性能方面也使用单独的数据库看起来更好的架构。

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.

另一个问题是如果元数据可以在运行时更改。元数据存储在 MetadataWorkspace 中。你可以阅读它们,但我不知道你是否也可以修改它们(我会在周末查看)。

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

这篇关于使用实体框架4在运行时更改表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆