How to import existing stored procedure in Entity Framework code-first from entity data wizard?

c# entity-framework-6 visual-studio-2017

Popular Answer

The processes don't need to be imported.

The code example demonstrates how to use the existing store operations "InsertStudent" and "UpdateStudent." Just need to overrideOnModelCreating method and map store procedures with entities.

Please see page zhttp://www.entityframeworktutorial.net/EntityFramework6/code-first-insert-update-delete-stored-procedure-mapping.aspxz for further details.

public class SchoolContext: DbContext 
{
   protected override void OnModelCreating(DbModelBuilder modelBuilder)
   {

     modelBuilder.Entity<Student>()
        .MapToStoredProcedures(p => p.Insert(sp => sp.HasName("InsertStudent").Parameter(pm => pm.StudentName, "name").Result(rs => rs.StudentId, "Id"))
            .Update(sp => sp.HasName("UpdateStudent").Parameter(pm => pm.StudentName, "name"))
            .Delete(sp => sp.HasName("DeleteStudent").Parameter(pm => pm.StudentId, "Id"))
        );
   }
}
0
10/2/2018 1:16:20 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow