实体框架4和多个数据库 [英] Entity framework 4 and multiple database

查看:79
本文介绍了实体框架4和多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么变化还是不支持?
例如join database1.dbo.Users和database2.dbo.Addresses

解决方案

您可以连接来自不同数据库的表,而不是不同的提供程序,导致将一个实体映射到来自不同数据库的两个或多个表或视图



如果您考虑这一点,当您使用Visual Studio创建EDM模型时,它会要求您提供一个现有的数据库,并且在完成创建模型后,会生成一个EF连接字符串,该连接字符串内部地址到给定的底层数据库连接字符串。 / p>

例如:元数据= res:// /EFTestModel.csdl/res/ /EFTestModel.ssdl/res /EFTestModel.msl;provider=System.Data.SqlClient; 提供者连接字符串=数据源= .\;初始目录= EFTest;集成安全= True; MultipleActiveResultSets = True *



所以每个模型只匹配一个数据库,只有一个连接字符串。



EF4仍然不支持创建一个适用于N个存储模型的概念模型。至少这不支持任何内置的提供程序。也许在未来,这可以通过一个新的提供商完成,它结合了许多存储(来自相同提供商或不同的)的支持。



我没有做足够的研究,但可能 Windows Server AppFabric(Codename Velocity)可能是通过这个空白的桥梁。



注意:我已经尝试手动编辑用于EDM(edmx)的xml将第二个元素插入&edimx:StorageModels>标签,但它不符合EDM XML模式,所以VS警告:
错误10021:遇到重复的模式元素。



Rafa Ortega
MAP2010


Something changes or it still not support this? For example join database1.dbo.Users and database2.dbo.Addresses

解决方案

I think what ais asked is if you can join tables from different databases, not different providers, resulting in one entity mapped to two or more tables or views from different databases.

If you think about it, when you create a EDM model with Visual Studio it ask you to give an existing database, and when finished creating the model, it generates an EF connection string, that internally address to the given underlying database connection string.

E.g: metadata=res:///EFTestModel.csdl|res:///EFTestModel.ssdl|res:///EFTestModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\;Initial Catalog=EFTest;Integrated Security=True;MultipleActiveResultSets=True"*

So each model matches only a database, only a connection string.

EF4 still does not support creating one conceptual model which works with N storage models. At least this is not supported with any built-in provider. Perhaps in the future this could be done through a new provider that combines the support of many storages (from the same providers or different).

I havent done enough research on it, but perhaps Windows Server AppFabric (Codename Velocity) could be the bridge to go through this gap.

Note: I have tried even editing manually the xml for the EDM (edmx) to insert a second element inside the <edmx:StorageModels> tag but it does not match the EDM XML Schema so VS warns about it: Error 10021: Duplicated Schema element encountered.

Rafa Ortega MAP2010

这篇关于实体框架4和多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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