在单个ASP.NET应用程序中使用实体框架的多个版本的SQL Server [英] Multiple Versions of SQL Server using Entity Framework in a single ASP.NET application

查看:193
本文介绍了在单个ASP.NET应用程序中使用实体框架的多个版本的SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用SQL Server 2000,2005和2008的Web应用程序中使用实体框架。当我使用除2008年以外的任何其他版本(第一个edmx版本)创建一个新的EDMX文件时,我收到 error 0172:所有SSDL工件必须定位到同一个提供程序。提供者'MyDatabase'不同于之前遇到的'MyDatabase'。似乎代码中某处连接已连接到一个2008数据存储区,当它检查SSDL文件并看到一个不同的ProviderManifestToken值会抛出此错误。我多一点沮丧。很难想象,EF只适用于每个应用程序的单个版本的Sql Server。我相当肯定必须有一个设置或解决方法。有人有解决方案可以在单个Web应用程序中使用不同版本的SQL Server和Entity Framework?

解决方案

我能够通过将每个 edmx 放在单独的程序集中来实现此目的。然后在连接字符串中,将所有 res:// * / ... 替换为 res:// NameOfAssembly / ...



我甚至可以在两个实体模型之间执行连接(与我在其他来源中发现的声明相反),例如:

  var oneDb = new Entities2000(); 
var otherDb = new Entities2005();

var results = from one in oneDb.SomeSet
在otherDb.OtherSet中加入其他
在一个.Property等于other.Property
选择新的{
SomeProp = one.SomeProp,
OtherProp = other.OtherProp
};


I am using the Entity Framework in a web application that utilizes SQL server 2000, 2005, and 2008. When I create a new EDMX file using anything other than 2008 (version of the first edmx created) I receive error 0172: All SSDL artifacts must target the same provider. The Provider 'MyDatabase' is different from ' MyDatabase ' that was encountered earlier. It seems that somewhere in the code the connection is wired to a 2008 datastore and when it checks the SSDL file and sees a different ProviderManifestToken value it throws this error. I am a little more than frustrated. It is hard to imagine that EF will only work with a single version of Sql Server per application. I am fairly sure there must be a setting or workaround. Does anyone have a solution to use different versions of SQL server and the Entity Framework within a single web application?

解决方案

I was able to accomplish this by putting each edmx in a separate assembly. Then in the connection string, replace all the res://*/... with res://NameOfAssembly/...

I can even perform joins between the two entity models (contrary to claims I found in other sources), e.g.:

var oneDb = new Entities2000();
var otherDb = new Entities2005();

var results = from one in oneDb.SomeSet
              join other in otherDb.OtherSet
                  on one.Property equals other.Property
              select new { 
                  SomeProp = one.SomeProp,
                  OtherProp = other.OtherProp 
              };

这篇关于在单个ASP.NET应用程序中使用实体框架的多个版本的SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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