Entity Framework:指定的架构无效。

3
我正在开发一个使用Entity Framework 5,Visual Studio 2012的Web应用程序,并且需要支持SQL Server和Oracle数据库提供程序。我为Oracle数据库创建了实体模型。我认为在连接字符串进行一些更改后它会起作用,但是不是那么容易...我找到了这篇文章:http://www.codeproject.com/Articles/82017/Preparing-an-Entity-Framework-model-for-multi-prov现在我得到以下错误 警告0005:未找到属性“版本”的架构信息。 我的_s_entity.ssdl(2,2):错误0010:在根元素中,命名空间http://schemas.microsoft.com/ado/2009/11/edmx中的元素Edmx是意外的。预期的模式在以下其中一个名称空间中:http://schemas.microsoft.com/ado/2006/04/edm/ssdlhttp://schemas.microsoft.com/ado/2009/02/edm/ssdlhttp://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个回答

1

添加项目引用EntityFramework.SqlServer.dll


1
我遇到了这个错误,这个解决方案 对我有用。
public MyContext : DbContext
{
    public MyContext() : base("name=MyContext")
    {
        // the terrible hack
        var ensureDLLIsCopied = 
                System.Data.Entity.SqlServer.SqlProviderServices.Instance;   
    }

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 版本与您尝试使用它的版本不匹配。


我已经检查过了,我正在使用Entity Framework 5。相同的模式路径适用于Oracle,但对于SQL Server则会出现错误。 - NMathur

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接