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”的引用。
  • 相关阅读:
    (转)AS3中实现卡马克卷轴算法
    (转)flash位图缓存cacheAsBitmap
    (转)addFrameScript函数的纠结
    (转)flash安全策略文件
    (转)脏矩形技术学习
    (转)stopImmediatePropagation 和stopPropagation的区别
    (转)flash对象池技术
    揭开嵌入式C面试题背后的玄机
    一次遍历找链表倒数第n个节点
    N!的尾部连续0的个数
  • 原文地址:https://www.cnblogs.com/TiestoRay/p/3425193.html
Copyright © 2011-2022 走看看