【问题标题】:Entity framework CTP5 Model compatibility cannot be checked because the database does not contain model metadata实体框架 CTP5 模型兼容性无法检查,因为数据库不包含模型元数据
【发布时间】:2011-03-01 05:10:17
【问题描述】:

我正在尝试使用现有表测试实体框架 CTP 5 Code First。

  1. 我定义了模型类和 DbContext 并运行了应用程序。它创建了数据库和表。
  2. 我从数据库中删除了EdmMetadata 表。
  3. 在我的连接字符串中添加了Trusted_Connection=true;Persist Security Info=True
  4. 当我再次运行应用程序时,出现此错误。

System.NotSupportedException 未被用户代码处理
Message=无法检查模型兼容性,因为数据库没有 包含模型元数据。
来源=实体框架

如何让这个应用程序在没有EdmMetadata 表的情况下运行?

【问题讨论】:

    标签: entity-framework entity-framework-4 ef-code-first


    【解决方案1】:

    如果您不想使用 EdmMetadata 表,请尝试将其添加到您的 DbContext 派生类中:

    protected override void OnModelCreating(ModelBuilder modelBuilder) 
    {
        modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
    }
    

    【讨论】:

    • 我添加了这个方法并运行了我得到这个错误的问题。 [NotSupportedException: Model compatibility cannot be checked because the EdmMetadata type was not included in the model. Ensure that IncludeMetadataConvention has been added to the ModelBuilder conventions.] 我删除并运行了没有创建 Edmmetadata 表的应用程序
    猜你喜欢
    • 2014-07-31
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 2016-03-19
    相关资源
    最近更新 更多