I have a site that was built using database first and I'm trying to continue development of it on a mac. Normally I would run the Scaffold-dbContext using the Console Package Manager in Visual Studio. The mac version doesn't have this I tried running it in Terminal, but that obviously didn't work. Is it possible to run this command, or do I need to continue development on Windows?
The above Scaffold-DbContext command creates entity classes for each table in the SchoolDB database and context class (by deriving DbContext ) with Fluent API configurations for all the entities in the Models folder. The following is the generated Student entity class for the Student table.
Entity Framework Core supports Database-First approach via the Scaffold-DbContext command of Package Manager Console. This command scaffolds a DbContext and entity type classes for a specified database.
Update the toolsUse dotnet tool update --global dotnet-ef to update the global tools to the latest available version. If you have the tools installed locally in your project use dotnet tool update dotnet-ef . Install a specific version by appending --version <VERSION> to your command.
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
You can run the command from the terminal after completing a few required steps as found here:
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With