【问题标题】:How to do Migrations and SQL Server connection on MacOS如何在 MacOS 上进行迁移和 SQL Server 连接
【发布时间】:2016-11-05 16:49:43
【问题描述】:

我在 OSX 中,我正在创建一个新的 ASP.NET Core Web API。我已经按照本教程进行操作:https://docs.efproject.net/en/latest/platforms/netcore/new-db-sqlite.html

这很酷,但是 Sql Server 呢?现在我知道 SQL Server 还不能在 OSX (https://www.microsoft.com/en-us/cloud-platform/sql-server-on-linux) 上运行。

我能看到的唯一方法是创建一个云远程 SQL 服务器(在 Azure 或类似服务器上),然后从我的 ASP.NET 核心应用程序连接它。我尝试遵循这个,但它假设 VS2015 https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html。我们在 VSCode 中没有包管理器控制台,我不知道是否有等效于 Scaffold-DbContext。

那么我该如何连接到 SQLServer 以及如何执行诸如 EF 迁移之类的操作来更新该数据库。

【问题讨论】:

    标签: sql-server macos asp.net-core entity-framework-core .net-core


    【解决方案1】:

    通过使用 project.json 和 dotnet restore (如果保存 project.json 时 VSCode 不这样做),可以在没有包安装程序的情况下完成所有包的下载。

    安装工具后,您可以使用 dotnet ef migrations add <migration name>dotnet ef database update 创建迁移,以将迁移应用到 db 架构。

    尚不支持类库(其中 DbContext 和模型在类库中定义)。不过,Entity Framework Core docs 中有一个解决方法。

    对于脚手架,用法是dotnet ef dbcontext scaffold [arguments] [options]。详情请见Scaffolding docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 2010-10-31
      • 1970-01-01
      相关资源
      最近更新 更多