How to do Migrations and SQL Server connection on MacOS

.net-core asp.net-core entity-framework-core macos sql-server

Question

I'm in OSX and I'm creating a new ASP.NET Core Web API. I've followed this tutorial: https://docs.efproject.net/en/latest/platforms/netcore/new-db-sqlite.html

That's cool and all but what about Sql Server? Now I know SQL Server won't yet run on OSX (https://www.microsoft.com/en-us/cloud-platform/sql-server-on-linux).

The only way I can see to make this work is if I create a cloud remote SQL server (on Azure or similar), then connect with it from my ASP.NET core application. I tried following this, but it assumes VS2015 https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html. We don't have the package manager console in VSCode and I don't know if there is an equivalent to Scaffold-DbContext.

So how do I make a connection to SQLServer and how do I do things like EF migrations to update that database.

1
2
7/4/2016 6:49:35 AM

Popular Answer

All the packages download can be done without the package installer, by using project.json and dotnet restore (if VSCode doesn't do it when project.json is saved).

With the tools installed, you can create migrations with dotnet ef migrations add <migration name> and dotnet ef database update to apply the migrations to the db schema.

Class libraries (where DbContext and models are defined in class library) are not supported yet. There is a workaround in the Entity Framework Core docs though.

For scaffolding the usage is dotnet ef dbcontext scaffold [arguments] [options]. See the Scaffolding docs for details.

1
7/4/2016 8:13:23 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow