zoukankan      html  css  js  c++  java
  • ef core code first from exist db

    目标

    为现有数据库生成新的连接,允许只选择部分表
    可以处理一些很怪的需求,比如EF升级EF Core(这个可能有其他解),EF、EF Core同时连接一个数据库
    我遇到的问题是:

    原项目是.net framework的,现在要引用identityserver 4,实现SSO,但是不能重建用户表,需要使用原有的由ef code first生成的用户表
    在经过多种方案之后,最终决定新建一个ef core,连接现有数据库
    

    操作

    安装包
    Microsoft.EntityFrameworkCore.SqlServer
    Microsoft.EntityFrameworkCore.Tools
    Microsoft.VisualStudio.Web.CodeGeneration.Design
    
    使用指令
    Scaffold-DbContext "Data Source=IP; Database=DbName; User ID=sa; Password=password;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Tables -Tables Table1,Table2
    

    参数说明:
    OutputDir 输出文件夹(这里取名为"Tables")
    Tables 选择的表,默认全部

    注意

    会生成一个dbcontext,如果该项目原有dbcontext,需要手动拷贝一下,主要是迁移Tables+OnModelCreating

    参考资料

    https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db

  • 相关阅读:
    爬虫入门(五)
    爬虫入门(四)
    爬虫入门(三)
    爬虫入门(二)
    爬虫入门(一)
    openpyxl的简单使用
    ansible(三)
    ansible(二)
    ansible(一)
    CF Global Round 10-F
  • 原文地址:https://www.cnblogs.com/Lulus/p/9469180.html
Copyright © 2011-2022 走看看