Reputation: 661
I use ASP.NET Core 6 and use Entity Framework with an existing database.
Since my database already exists, I need to do reverse engineer to generate the code based on the existing database. I have seen some tutorials which show how I can do it. But what I see is, I am only able to get the tables but not other objects like, stored procedure, views, functions or triggers.
I have two questions:
When working with the database first approach where the database already exists in EF Core, when reverse engineering do I have to generate code for the other objects like I mentioned above, stored procedures, views and other?
Is it optional or must I have them?
If they are required how can I generate them in C# code?
Upvotes: 0
Views: 756
Reputation: 640
You can only generate models from existing database using this command -
DOTNET CLI:
dotnet ef DBContext scaffold "Server=.;Database=db_name;User Id=user_id;Password=password" Microsoft.EntityFrameworkCore.SqlServer -o Models
PACKAGE MANAGER CONSOLE:
Scaffold-DbContext "Server=.;Database=db_name;Trusted_Connection=True;Id=user_id;Password=password" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
This command will reverse engineer db tables to models.
Upvotes: 1