zoukankan      html  css  js  c++  java
  • Entity Framework 异常档案

    1.异常

    The model backing the 'DBContext' context has changed since the database was created.
    Consider using Code First Migrations to update the database

    原因是没有添加初始化数据,解决方法

    System.Data.Entity.Database.SetInitializer(new XX.SampleData());

    System.Data.Entity.Database.SetInitializer<XXModelContext>(null
    );
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Data.Entity;
    
    namespace XX
    {
        public class SampleData : DropCreateDatabaseIfModelChanges<XXModelContext>
        {
            protected override void Seed(XXModelContext context)
            {
                var m= new List<XXModel>
                {
                    new XXModel(),new XXModel()
                }.ForEach(a => context.XXModels.Add(a));
            }
        }
    }

     也可以通过NPM控制台处理  :update-database -force


    2.“System.Data.Objects.ObjectContext”在未被引用的程序集中定义。

    使用EF的CodeFirst时,我们一般会这样写

    public class DBContext:DbContext
    {
        public DBContext(string conn)
            : base(conn)
        {
        }
    }

    虽然引用了EntityFrame.dll 但有时候会出现下面这个错误

    类型“System.Data.Objects.ObjectContext”在未被引用的程序集中定义。必须添加对程序集“System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。

    解决方法:引用System.Data.Entity.dll即可


    错误    1    类型“System.Data.Objects.ObjectContext”在未被引用的程序集中定义。必须添加对程序集“System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。
  • 相关阅读:
    careercup-树与图 4.6
    careercup-树与图 4.5
    careercup-树与图 4.4
    careercup-树与图 4.3
    oracle 建表时显示ORA-00904无效的标识符
    Unable to read TLD "META-INF/c.tld" from JAR file
    MIME TYPE
    JavaWeb response对象常用操作
    移动硬盘文件删除后,空间没有变大
    Redis 数据结构解析和命令指南
  • 原文地址:https://www.cnblogs.com/TiestoRay/p/3425193.html
Copyright © 2011-2022 走看看