Today I'm simulating code first with an existing database approach. But on Entity Data Model Wizard in VS 2017 -> Import selected stored procedures an functions into the entity model check box is disabled. Please see attached screenshot:
So how do I enable that option?
You don't need to import the procedures.
Use of exisitng store procedures(InsertStudent,UpdateStudent) are shown in code sample. Just need to override OnModelCreating
method and map store procedures with entities.
Kindly refer to this page http://www.entityframeworktutorial.net/EntityFramework6/code-first-insert-update-delete-stored-procedure-mapping.aspx for detailed information.
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"))
);
}
}