0

我有 mvc 3 应用程序,其中在会话对象中我将我需要的所有值作为参数来执行存储过程。

如果 userAction 是更新,则执行存储过程。

  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);
    }

如何从 Session[Mappings] 中获取值并将其传递给存储过程?

4

1 回答 1

2

你需要做这样的事情:

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

...其中MyEntitiesDataModel是您的 EF 数据模型,而MyStoredProc是您的存储过程的名称。

于 2012-04-20T15:25:53.957 回答