实体框架:指定的模式无效

时间:2013-12-12 11:17:30

标签: sql-server oracle entity-framework

我正在开发一个使用Entity Freamwork 5 Visual Studio 2012的Web应用程序,它需要同时支持SQL Server和Oracle数据库提供程序。我为Oracle数据库创建了实体模型。我认为在连接线发生一些变化之后它会起作用,不是没有那么容易..我发现这个帖子:

http://www.codeproject.com/Articles/82017/Preparing-an-Entity-Framework-model-for-multi-prov

现在我收到了以下错误

  

指定的架构无效。错误:my_s_entity.ssdl(2,12):   警告0005:找不到该属性的架构信息   '版'。 my_s_entity.ssdl(2,2):错误0010:元素Edmx in   名称空间http://schemas.microsoft.com/ado/2009/11/edmx出乎意料   对于根元素。以下之一中的预期架构   名称空间:http://schemas.microsoft.com/ado/2006/04/edm/ssdl,   http://schemas.microsoft.com/ado/2009/02/edm/ssdl,   http://schemas.microsoft.com/ado/2009/11/edm/ssdl

堆栈追踪:

[MetadataException: Schema specified is not valid. Errors: 
my_s_entity.ssdl(2,12) : warning 0005: Could not find schema information for the attribute 'Version'.
my_s_entity.ssdl(2,2) : error 0010: The element Edmx in namespace http://schemas.microsoft.com/ado/2009/11/edmx was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm/ssdl, http://schemas.microsoft.com/ado/2009/02/edm/ssdl, http://schemas.microsoft.com/ado/2009/11/edm/ssdl.]
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +965
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Control.PreRenderRecursiveInternal() +168
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974

我在网上搜索过但无法解决任何问题。为什么我会遇到这个问题?如果每个人都面临同样的问题,请分享。

3 个答案:

答案 0 :(得分:1)

将项目引用添加到EntityFramework.SqlServer.dll

答案 1 :(得分:1)

我遇到此错误,This solution对我有用

public MyContext : DbContext
{
    public MyContext() : base("name=MyContext")
    {
        // the terrible hack
        var ensureDLLIsCopied = 
                System.Data.Entity.SqlServer.SqlProviderServices.Instance;   
    }

答案 2 :(得分:0)

如果您在xml编辑器中打开您的edmx文件,它应如下所示:

<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
  <edmx:Runtime>
   <edmx:StorageModels>
<Schema Namespace="XXX.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">

xmlns命名空间与您正在使用的EF版本之间存在关系。在您创建模型的EF版本中存在一些不匹配以及您尝试使用它的位置。