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的功能。

    所谓人才,就是你接给他一件事情,他做成了;你再交给他一件事情,他又做成了。
  • 相关阅读:
    ajax的一些知识
    前端性能优化汇总
    jquery实现一些小动画二
    python简单日志处理
    逆波兰式---C实现
    java常见异常
    Hive与HBase集成及常见问题解决
    SQL for HBase
    Demystifying the Skip Scan in Phoenix
    Difference between DDL, DML and DCL commands
  • 原文地址:https://www.cnblogs.com/frankliu/p/4791804.html
Copyright © 2011-2022 走看看