简体   繁体   English

实体框架配置驱动

[英]Entity Framework Configuration Driven

I have two web services which are identical to each other apart from the configuration files. 除了配置文件之外,我还有两个彼此相同的Web服务。 However, both use Entity Framework 4 to store their data in a table and are currently pointing to the same table. 但是,两者都使用Entity Framework 4将数据存储在表中,并且当前都指向同一表。 How can I split these to use different tables based on some configuration setting. 如何根据某些配置设置将它们拆分为使用不同的表。

Ideally I do not want to create a seperate database as I will have several of these types of twin services and my hosting provider charges more for extra database instances. 理想情况下,我不想创建一个单独的数据库,因为我将拥有其中几种类型的孪生服务,而且我的托管服务提供商会为额外的数据库实例收取更多的费用。 Also each table should logically belong to the same database. 同样,每个表在逻辑上应属于同一数据库。 I want the two models to point to two identical tables with different names. 我希望这两个模型指向两个具有不同名称的相同表。 Is this possible. 这可能吗。

UPDATE 更新

If there is no method of doing this. 如果没有这样做的方法。 I can make a copy of the entity and use a config entry to switch between the two models. 我可以制作实体的副本,并使用config条目在两个模型之间切换。

I think the only possible way is extracting CSDL, MSL and SSDL files from EDMX file. 我认为唯一可能的方法是从EDMX文件中提取CSDL,MSL和SSDL文件。 You will need separate SSDL and MSL for each type of configuration. 对于每种类型的配置,您将需要单独的SSDL和MSL。 SSDL is XML describing database tables and MSL is XML describing mapping between objects and table. SSDL是描述数据库表的XML,而MSL是描述对象和表之间的映射的XML。 You will have to rename table in second set of these files. 您将不得不在第二组这些文件中重命名表。 Then you will use connection string using correct set of these files in your each deployment scenario. 然后,您将在每个部署方案中使用正确的这些文件集来使用连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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