Is OR/M available in .NET core web API project?

ado.net asp.net-core c# entity-framework-core visual-studio

Question

In ASP.NET Framework projects one could right click the project and add a ADO.NET Entity Data Model using an existing database. This would create classes and properties from database's tables and columns.

But this option is missing from ASP.NET Core API web application project. What can I use to create these classes from existing SQL Server database, or is that not possible?

VS add ORM to project

1
0
2/13/2020 7:39:25 AM

Accepted Answer

This worked

In Package Manager Console:

  1. Install-Package Microsoft.EntityFrameworkCore.Tools
  2. scaffold-dbcontext "your_connection_string" Microsoft.EntityFrameworkCore.SqlServer -outputdir Models -Table table1,table2

If you get an error that "The term 'scaffold-dbcontext' is not recognized as the name of a cmdlet...", see this question: The term 'scaffold-dbcontext' is not recognized as the name of a cmdlet, function, script file, or operable program

-1
3/10/2020 9:56:30 PM

Popular Answer

Try to execute the following command under your project folder:

$ dotnet ef dbcontext scaffold "Server=....." Microsoft.EntityFrameworkCore.SqlServe
r -o Models

And fill the string Server=..... with your database connection string. Make sure that you can connect to this database successfully.

command

And EF will try to build models from the database.

generated

Reference: https://anduin.aiursoft.com/post/2020/2/13/creating-a-model-for-an-existing-database-in-entity-framework-core



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