I can use EF Core Power Tools to scaffold stored procedures, but how can I do it in code?

D Simmons 0 Reputation points
2024-11-28T14:50:04.8666667+00:00

I can scaffold the tables in a database using the following:

Scaffold-DbContext "Server=SQLServer;Database=Database;User Id=User;Password=Password; Trusted_Connection=True; TrustServerCertificate=True; Integrated Security=False; Encrypt=False" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Data/Migrations -ContextDir Data

But this will not scaffold the stored procedures. I can go into EF Core Power Tools, and check the box to have the stored procedures scaffolded along with the Database, but I want to do it with code.

How do I do that?

Thanks,

Community Center | Not monitored
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,006 Reputation points Volunteer Moderator
    2024-11-28T16:33:20.5366667+00:00

    What do you mean by code? The EF power tools are an open source visual studio extension for reverse engineering, that is database first. There is no code first support for stored procedures. if you are using database first, you should create a separate database project. Database project have tools for deploying updates.

    0 comments No comments

  2. D Simmons 0 Reputation points
    2024-11-28T17:05:43.75+00:00

    I used "code" loosely here, but was meaning text I put at the prompt of the Package Manager Console to Scaffold a database. Looking at all the parameters for scaffolding, I don't see an option or parameter to add stored procedures. I thought there may some sort of trick to it, since EF Power Tools will scaffold the Stored Procedures.

    Again, EF Power Tools is presently moving the Stored procedures into Migrations for me. I don't know that you would necessarily call it "code first' for Stored procedures, but what it accomplishes is what I am looking for.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.