I am trying to call multiple stored procedures from one controller in my MVC5 web application. I then combine the results of the two procedures into one model.
public ActionResult ItemDetails(string itemNo, string custNo)
{
SqlParameter[] param =
{
new SqlParameter("@itemNo",itemNo),
new SqlParameter("@custNo", custNo)
};
var sqlData = itemDb.Database.SqlQuery<ItemDetailsModel>("ItemDetail @itemNo, @custNo", param).ToList();
var whsID = new SqlParameter("@warehouse", sqlData?[0].WhsID);
var sqlData2 = itemDb.Database.SqlQuery<ItemDetailsModel>("ItemPoLookup @itemNo, @warehouse", new SqlParameter("@itemNo", itemNo), whsID).ToList();
sqlData.AddRange(sqlData2);
return View(sqlData);
}
Is it possible to make this happen while keeping the models separate? Should I do two get requests to my web server, one for each stored procedure, instead of combining this all into one? And if so advice on returning multiple models to the cshtml view would be appreciated.