How to send a procedure stored in the controller in ASP.NET MVC and Entity framework

0

I have this code in my controller and my stored procedures are already mapped. I access the database through Entity framework and the edmx is defined. I would like to know what the code is like to send (use) my stored procedure to create a new record.

public class pruebacontroller:controller
 private pruebaxEntities db=new pruebaxEntities();

public Action Result Index()

{

return View(db.spmotrartabla().ToList());//Me muestra la tabla a través de un procedimiento almacenado  y ya cree su vista

}

//Quiero saber que código va en esta parte para mandar llamar el procedimiento almacenado para crear

public Action Result Create()
{
  return View();
}

[httpPost]
public ActionResult Create (FormCollection collection)
try

{
  return RedirectToAction("Index")
}

catch

{
   return View();
}
    
asked by senseilex 22.06.2017 в 18:32
source

1 answer

0

You have to create an ObjectParameter that will return the output parameters, the input parameters should be in the order as you defined it in your Stored Procedure.

ObjectParameter parametroOut1 = new ObjectParameter("NombreParametro", typeof(String));
db.NombredelProcedimiento(valor1,valor2,valor3, parametroOut1);
Console.WriteLine(name.Value);
    
answered by 22.06.2017 / 19:08
source