0

I am working on an ASP.NET Core project with Entity Framework Core. I took the code first approach and I am able to create tables through it.

Now I want to create a stored procedure, as well as the already created stored procedure, which needs to be mapped.

1
  • The only way is to actually execute the CREATE PROCEDURE script. You may do that in a migration, but you still have to write the full script yourself. Instead of trying to write the script as a C# string though it's probably (a lot) better to write it in a text file with .sql extension so you get editor highlighting and even execution if the editor supports it (VS Code does) Commented Jul 29, 2022 at 13:02

1 Answer 1

1

First add a migration: add-migration stored-procedures or something. Then open the migration and enter your SQL to create or drop the stored procedure in the following way.

protected override void Up(MigrationBuilder migrationBuilder)
{
  migrationBuilder.Sql("SQL TO CREATE STORED PROC");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
  migrationBuilder.Sql("SQL TO DROP STORED PROC");
}
Sign up to request clarification or add additional context in comments.

1 Comment

So, it's only possible with migrations? Would be nice to have it since "OnModelCreating"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.