Multiple Versions of SQL Server using Entity Framework in a single ASP.NET application

笑着哭i 提交于 2019-11-30 08:11:31

问题


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?


回答1:


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 
              };



回答2:


This link helped me to solve the problem when there was a difference in SQL server 2005 and 2008. http://kkryczka.wordpress.com/2011/01/03/all-ssdl-artifacts-must-target-the-same-provider-the-providermanifesttoken-2008-is-different-from-2005-that-was-encountered-earlier/

Right click on the .edmx file and select Open with XML Editor. Open Entity Framework .edmx file:

Change the ProviderManifestToken to 2008:

Looks like its a known issue for Microsoft.



来源:https://stackoverflow.com/questions/1061409/multiple-versions-of-sql-server-using-entity-framework-in-a-single-asp-net-appli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!