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

    所谓人才,就是你接给他一件事情,他做成了;你再交给他一件事情,他又做成了。
  • 相关阅读:
    移动端 异常捕获
    禁止选中网页的某段文字
    Java正则表达式的解释说明
    error while performing database login with the xxx driver
    javascript 日期转换为中文
    chrono使用
    resize
    github使用
    adb 无法连接 CreateProcess failure, error 2 * could not start server *
    opencv-videowriter
  • 原文地址:https://www.cnblogs.com/frankliu/p/4791804.html
Copyright © 2020-2023  润新知