为什么型号的兼容性不能被选中? [英] Why Model compatibility cannot be checked?

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

问题描述

我不得不从恩collega进一步工作。所以,我不跑数据库asp.net的解决方案。它创建了一个数据库。我认为这是code首先或code首先迁移。

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.

然后我试图在去UI一些测试,并得到这个消息:

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

型的System.NotSupportedException异常发生在
  EntityFramework.dll而不是在用户code处理

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

更多信息:型号的兼容性不能被选中,因为
  该数据库不包含模型元数据。型号兼容性能
  只检查使用code首先创建的数据库或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.

这是code其中日消息从何而来。

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?

推荐答案

DropCreateDatabaseIfModelChanges 初始化删除并重新创建数据库,如果数据库架构不再在$相匹配的类C $℃。它决定:如果模型的变化通过看你的类,并在寻找一个叫 _MigrationHistory 数据库中的表。如果不存在这样的表,它引发了问题的异常。

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:


  • 使用不同的初​​始化(如 DropCreateDatabaseAlways )或

  • 确保有在你的数据库中的 _MigrationHistory 表中,通过启用的实体框架code首先迁移的。

  • Use a different initializer (such as DropCreateDatabaseAlways) or
  • Make sure that there is a _MigrationHistory table in your database, by enabling Entity Framework code first migrations.

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

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