0

I have mvc 3 application in which in session object i'm taking all values that is needed to me as parameter to execute stored procedure.

If the userAction is update then execute stored procedure.

  public ActionResult Index(string userAction)
    {
       if(Session["Mappings"] != null)           
            ViewData["Message"] = "Mapping web grid";

        if (Session["PricingSecurities"] == null)
            Session["PricingSecurities"] = objRepository.GetPricingSecurityID();
        if (Session["Cusips"] == null)
            Session["Cusips"] = objRepository.GetCUSIP();

        SecurityMappingModel objModel = null;
        mappings = (List<SecurityMappingModel>)Session["Mappings"];

        objModel = new SecurityMappingModel();


        if (userAction == "Update" )
        {
            //please tell me how can i take values from Session[Mappings] and pass it to stored procedure?

            return RedirectToAction("Index");
        }
        objModel.PricingSecirities = (List<SelectListItem>)Session["PricingSecurities"];
        objModel.Cusips = (List<SelectListItem>)Session["Cusips"];
        ViewBag.Mappings = mappings;
        return View(objModel);
    }

How can i take values from Session[Mappings] and pass it to stored procedure?

tereško
  • 58,060
  • 25
  • 98
  • 150
Neo
  • 15,491
  • 59
  • 215
  • 405
  • 1
    are you using entity framework? – Rafay Apr 20 '12 at 06:57
  • why no one dont know how to execute sp in mvc ;( – Neo Apr 20 '12 at 08:46
  • http://stackoverflow.com/questions/6219643/how-to-call-stored-procedure-in-mvc-by-ef – VJAI Apr 20 '12 at 09:31
  • yes i have gone trough ... thanks but i want to know that in my case how can i do this as in `Session["Mappings"]` all my 3 parameters how can i get those values and pass it to stored procedure? – Neo Apr 20 '12 at 11:34

1 Answers1

2

You would need to do something like this:

    using (MyEntitiesDataModel context = new MyEntitiesDataModel())
    {
        context.ExecuteStoreCommand(
            "exec MyStoredProc @param1={0}, @param2={1}",
            Session["foo"], Session["bar"]);
    }

...where MyEntitiesDataModel is your EF data model and MyStoredProc is the name of your stored proc.

Ivan Karajas
  • 1,081
  • 8
  • 14