Jashvita
Jashvita

Reputation: 661

.NET Core Entity Framework: updating C# code for existing database for tables and other objects

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:

  1. 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?

  2. Is it optional or must I have them?

  3. If they are required how can I generate them in C# code?

Upvotes: 0

Views: 756

Answers (1)

Tamzid Ahmed
Tamzid Ahmed

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

Related Questions