致虚极,守静笃!

Entity Framework Core Update Database

Entity Framework Core Update Database

当数据结构改变后更新数据库

方式一:

菜单-> Tooles->External Tools-> Add

  1. Title: Update DbContext
  2. Command: dotnet.exe
  3. Arguments: ef dbcontext scaffold "your-connection-string" Microsoft.EntityFrameworkCore.SqlServer --output-dir=Models --force
  4. Initial Directory: $(ProjectDir)
  5. 点击Apply 和 Ok
  6. Tools菜单会出现 Update DbContext点击即可
  7. 连接字符串貌似得使用带有密码的否则会报instance failure
方式二:
  1. 如果是Package Manager Console:

    Scaffold-DbContext "Server=(localdb)\v11.0;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force

  2. 如果是CLI Commands:

    dotnet ef dbcontext scaffold "Server=(localdb)\v11.0;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models -f

  3. 这会导致指定文件夹的内容被重写.

posted @ 2021-01-18 14:11  Baron-Li  阅读(407)  评论(0编辑  收藏  举报

致虚极,守静笃!