# Calling Stored Procedure “insert query” using EF 6, UOW, and MVC 5

I'm a beginner in MVC programming, repository, and UOW using Entity framework. I tried to calling my existing SP in my MVC project using UOW and EF.

Here is my code to mapping my SP in myDbContext file:

modelBuilder.Entity<Applicant>().MapToStoredProcedures(
s => s.Insert(
i => i.HasName("InsertApplicant")
.Parameter(fn => fn.First_Name,"FirstName")
.Parameter(ln => ln.Last_Name,"LastName")
.Parameter(em => em.Email,"Email")
.Parameter(tn => tn.Tel_No,"TelNo")
.Parameter(mn => mn.Mobile_No,"MobileNo")
.Parameter(vt => vt.Visa_Type,"VisaType")
.Parameter(ob => ob.Objective, "Objective")
.Parameter(ac => ac.Active, "Active")));


And, below is the code I used to call the SP on my controller (i don't know if it's right or not):

using (var context = new MyExperienceDbContext())
{
var fn = new SqlParameter("@FirstName", entity.First_Name);
var ln = new SqlParameter("@LastName", entity.Last_Name);
var em = new SqlParameter("@Email", entity.Email);
var pn = new SqlParameter("@TelNo", entity.Tel_No);
var mn = new SqlParameter("@MobileNo", entity.Mobile_No);
var vt = new SqlParameter("@VisaType", entity.Visa_Type);
var ob = new SqlParameter("@Objective", entity.Objective);
var ac = new SqlParameter("@Active", entity.Active);

fn, ln, em, pn, mn, vt, lu, ob, ac);
return RedirectToAction("Index");
}


It works fine for me, but I noticed if I delete the mapping's code in myDbContext file everything still works fine. I believe i'm failed to implemented the UOW and repository concept in EF when calling my existing SP, right? Do you have any idea with my question above or do you have tutorial suggestion to calls SP using UOW and EF in MVC project?

• Providing tutorials by themselves is not what we do here. Answerers can always recommend some along with a code review. – Jamal Mar 3 '15 at 6:17

Your mapping is designed to call a stored procedure when you call context.Applicants.Add() and context.SaveChanges(). Your second code manually calls a stored procedure, that is not what you want to do. Simply keep your mapping:

using(var context = new MyExperienceDbContext())
{

public interface IApplicantRepository