Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No CreateStoredProcedure method on Entity Framework Core

I want to create stored procedure using Migration Builder but there is no

CreateStoredProcedure

method in Migration class like this.

public override void Up() 
{
  CreateStoredProcedure(
    "MyStoredProcedure",
    p => new
    {
        id = p.Int()
    },
    @"SELECT some-data FROM my-table WHERE id = @id"
  );
}

public override void Down() 
{
  DropStoredProcedure("MyStoredProcedure");
}

How to Create Stored procedure in Migration using Entity Framework Core?

like image 714
Radenko Zec Avatar asked Jul 06 '16 11:07

Radenko Zec


People also ask

How can we call stored procedure in Entity Framework in .NET core?

The support for stored procedure in EF Core is similar to the earlier versions of EF Code first. You need to create your DbContext class by inherting the DbContext class from EF. The stored procedures are executing using the DbContext. First step is to write a method that create a DbCommand from the DbContext.

Does EF core support stored procedures?

EF Core already supports querying data from stored procedures. This feature will allow mapping the inserts, updates, and deletes generated by SaveChanges to stored procedures in the database.

What is the use of FromSqlRaw method in Entity Framework Core?

FromSqlRaw method ( DbSet. FromSql prior to Entity Framework Core 3.0) enables you to pass in a SQL command to be executed against the database to return instances of the type represented by the DbSet : public class Book.


1 Answers

Use can use the migrationBuilder.Sql() method to execute arbitrary SQL in migrations with EF Core

like image 187
ErikEJ Avatar answered Oct 14 '22 10:10

ErikEJ