zoukankan      html  css  js  c++  java
  • Entity framework code first

           EF Code First 不便之处,数据库结构改变时,需要利用程序包管理器控制台生成代码,再用update-database -Verbose更新数据库,这样的做法在很多时候不容易部署。下面介绍一种可以简单部署到服务器的办法。

          执行add-migration Initial 生成迁移代码,具体过程网上资料很多,不多赘述;然后在Global启动时添加如下代码:

    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using System.Data.Entity.Migrations.Design;

    ToolingFacade facade = new ToolingFacade(typeof(iWS.PMS.Business.Admin).Assembly.FullName,
    typeof(iWS.PMS.Business.Admin).Assembly.FullName,
    typeof(iWS.PMS.Business.Migrations.Configuration).FullName,
    AppDomain.CurrentDomain.BaseDirectory + "bin",
    AppDomain.CurrentDomain.BaseDirectory + "Web.config",
    null,
    new DbConnectionInfo(Constant.ConnectionName.EntityString));

    //更新数据库
    facade.Update(null, false);

    你会发现以上代码实现了update-database -Verbose的功能。

    所谓人才,就是你接给他一件事情,他做成了;你再交给他一件事情,他又做成了。
  • 相关阅读:
    DHCP DHCPv6
    DHCPv6协议
    IPv6邻居发现协议
    CentOS下禁止防火墙
    centOS下更新yum源
    centOS下yum报错
    Flink+Kafka整合的实例
    Flink基本概念
    Ubuntu16.04下配置ssh免密登录
    Zookeeper+Kafka的单节点配置
  • 原文地址:https://www.cnblogs.com/frankliu/p/4791804.html
Copyright © 2011-2022 走看看