Stored procedure in Entity Framework database first approach

前端 未结 3 1015
渐次进展
渐次进展 2020-12-14 13:27

I am doing transition for a project from Webforms to MVC application using Entity Framework database first approach and have database ready along with all stored procedures

3条回答
  •  借酒劲吻你
    2020-12-14 13:33

    I implemented it through this well explained link to use stored procedures for CUD (create, update, delete) operations for an entity in the database-first approach.

    Steps I followed (concept is still unclear for me, but it worked as per my requirement), but I hope it may help someone else as well:

    1. Added ADO Entity Data Model using Database First Approach.

    2. Added a new Controller for my entity using "MVC5 Controller with Views using EF" option.

    3. For the DeleteConfirmed() function, i made minor changes as below:

       [HttpPost, ActionName("Delete")]
       [ValidateAntiForgeryToken]
       public ActionResult DeleteConfirmed(int eid,bool isdeletede)
       {
           emp emp1 = db.emp.Find(eid,isdeletede); //Composite Key in my Entity: Emp
           //  db.emp.Remove(emp_sd1);         
           db.sp_deleteempt1(eid);    //I excluded Remove() and invoked my  Stored Procedure & it worked well for me
      
           db.SaveChanges();
           return RedirectToAction("grpindex");
       }
      

提交回复
热议问题