Retrieve Stored Procedure Output Parameters in Entity Framework always null

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 23:58:04

You have to enumerate your result in order to actually execute the stored procedure. Try this:

public List<searchProducts_Result> GetProducts()
{
   var nameParam = new ObjectParameter("numbers", typeof(int));
   List<searchProducts_Result> listobjs = new List<searchProducts_Result>();

   // List<searchProducts_Result> objResult = null;

   searchProducts_Result outParam = new searchProducts_Result();
   using (var db = new SPWebEntities())
   {
      // by calling ToList() you execute the SP
      List<searchProducts_Result> objResult =
          db.searchProducts("asd", 2, 5, "15", nameParam).ToList();

      if (nameParam.Value != null)
         outParam.UserID = nameParam.Value.ToString();
      else
         outParam.UserID = "0";
      listobjs.Add(outParam);

      foreach (searchProducts_Result sr in objResult)
      {
         listobjs.Add(sr);
      }
   }

   return listobjs;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!