为什么不能检查模型兼容性? [英] Why Model compatibility cannot be checked?

查看:93
本文介绍了为什么不能检查模型兼容性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不从一个合唱团中进一步工作。所以我运行asp.net解决方案没有数据库。并创建了一个数据库。我认为这是Code First或Code First Migrations。



然后我在de UI中尝试了一些测试,并得到这个消息:



EntityFramework.dll中出现类型System.NotSupportedException的异常,但未在用户代码中处理



附加信息:无法检查模型兼容性,因为
数据库不包含模型元数据。模型兼容性
只能使用Code First或Code First
迁移创建的数据库进行检查。


这是消息来自的代码。

  public class TemInitializer:System.Data.Entity.DropCreateDatabaseIfModelChanges< ApplicationDbContext> 
{
public override void InitializeDatabase(ApplicationDbContext context)
{
base.InitializeDatabase(context);
}
}

有人可以告诉我如何解决这个问题,需要查看?

解决方案

初始化器删除并重新创建数据库 c>如果数据库模式不再匹配代码中的类。它通过查看你的类并通过查看数据库中名为 _MigrationHistory 的表来确定是否改变模型。如果没有这样的表,它会在问题中抛出异常。



所以要解决这个问题,你可以:




I had to work further from a ex collega. So I run the asp.net solution without database. and it created a database. I think this is Code First or Code First Migrations.

Then I tried some tests in de UI and get this message:

An exception of type 'System.NotSupportedException' occurred in EntityFramework.dll but was not handled in user code

Additional information: Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.

This is the code where de message come from.

public class TemInitializer : System.Data.Entity.DropCreateDatabaseIfModelChanges<ApplicationDbContext>
{
    public override void InitializeDatabase(ApplicationDbContext context)
        {
            base.InitializeDatabase(context);
        }
}

Can anybody tell me how to solve this or where i need to look?

解决方案

The DropCreateDatabaseIfModelChanges initializer drops and recreates the database if the database schema no longer matches the classes in your code. It determines "if model changes" by looking at your classes and by looking at a table called _MigrationHistory in the database. If there is no such table, it throws the exception in the question.

So to solve this, you can:

这篇关于为什么不能检查模型兼容性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆