实体框架无法检查CTP5模型兼容性,因为数据库不包含模型元数据

时间:2011-03-01 05:10:17

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

我正在尝试使用现有表测试Entity Framework CTP 5 Code First。

  1. 我定义了模型类和DbContext并运行了应用程序。它创建了数据库和表。
  2. 我从数据库中删除了EdmMetadata表。
  3. 在我的连接字符串中添加了Trusted_Connection=true;Persist Security Info=True
  4. 当我再次运行应用程序时,它会给我这个错误。
  5. System.NotSupportedException was unhandled by user code
    Message=Model compatibility cannot be checked because the database does not contain model metadata.
    Source=EntityFramework

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

1 个答案:

答案 0 :(得分:6)

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

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