• 二、core abp 数据库迁移


    一、数据库迁移-ABP(库)

    1、配置链接数据库:

     贴以下代码:

    {
      "ConnectionStrings": {
        "Default": "Server=47.101.53.168;database=ABP_mytest;user=xx;password=vs..127134;"
      },
      "Authentication": {
        "JwtBearer": {
          "IsEnabled": "true",
          "SecurityKey": "CoreABP_C421AAEE0D114E9C",
          "Issuer": "CoreABP",
          "Audience": "CoreABP"
        }
      },
      "Logging": {
        "IncludeScopes": false,
        "LogLevel": {
          "Default": "Debug",
          "System": "Information",
          "Microsoft": "Information"
        }
      }
    }

     2、迁移实践

    选择程序包源nuget.org以及类库为.EntityFrameworkCore 执行命令:

    迁移命令:
    
    Add-Migration InitialCreat             //对比当前数据库和模型的差异,生成相应的迁移类代码,使数据库和模型匹配的。
    
    Update-Database
    

      迁移命令集合:

    Update-Database -verbose   //更新数据库
    

      

    3、查看数据库是否成功

     

     选中Mvc 点击运行账号 admin  密码123qwe

    二、数据库迁移-项目(库)

    1、创建实体(.Core类库内创建一个存放项目表的文件夹 存放一个表一个类文件)

    using Abp.Auditing;
    using Abp.Domain.Entities;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace YD.CloudTimetable.Academic
    {
        [Table("Academic")]
        [Audited]
        public class Academic : Entity, IMayHaveTenant
        {
            public int? TenantId { get; set; }
    
            public virtual string Name { get; set; }
        }
    }
    

      

    2、.EntityFrameworkCore类库->EntityFrameworkCore文件夹->Repositories文件夹->DbContext.cs上下文数据库操作类 添加

    例如:       public virtual DbSet<Test11> Test11s { get; set; }

    3、控制台 选择.EntityFrameworkCore类库执行命令

    Add-Migration t_user    蕴意为 表    生成迁移文件为 日期+名称          //对比当前数据库和模型的差异,生成相应的迁移类代码,使数据库和模型匹配的。
    
    Update-Database                   //开始更新
  • 相关阅读:
    常用加密解密类(含3des)
    谷歌API(Ajax)
    flashpaper使用详解
    布置小窝
    CodeSimth数据访问层模板
    CodeSmith业务逻辑层模板
    CodeSimth生成实体类模板
    C# 参考之方法参数关键字:params、ref及out
    ALV 格式常用参数
    BOM输出
  • 原文地址:https://www.cnblogs.com/fger/p/10642473.html
Copyright © 2020-2023  润新知