Run Scaffold-DbContext on Visual Studio for Mac
You can run the command from the terminal after completing a few required steps as found here:
- You need to add the following manually to your *.csproj
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
- Execute
dotnet add package Microsoft.EntityFrameworkCore.Design
3.Execute
dotnet restore
You should now be able to scaffold using the command:
dotnet ef dbcontext scaffold --help
Here is the code work for me on visual studio mac
Install the below package using visual studio mac edit references on project or add package to .csproj file.
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.VisualStudio.Web.CodeGeneration.Design
or using the Terminal navigate to the project and use the below command -
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.EntityFrameworkCore.Tools
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
Now check the tools and EF are installed or not.Navigate to the project install location and use mac terminal with below command. It should show entity framework details
dotnet ef
Now Scaffold the DB context
dotnet ef dbcontext Scaffold "Server=<servername>,1433;Initial Catalog=<dbName>;Persist Security Info=False;User ID=<userID>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"Microsoft.EntityFrameworkCore.SqlServer -o <directory name>
References
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet
https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db
https://www.learnentityframeworkcore.com/walkthroughs/existing-database
I just wanted to post my solution after I struggled for a while. Had to separate the schema string into multiple --schema options.
dotnet ef dbcontext scaffold "Server=<servername>,1433;Initial Catalog=<dbName>;Persist Security Info=False;User ID=<userID>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer --context [context] -f --output-dir [dir] --schema [schema1] --schema [schema2]