Razor - Best way to get result from Stored Procedure
I have a complex stored procedure that always returns basic data (integers) in 1 row and 20 columns. I need to simply call the stored procedure and display the result on my razor page.
I'm able to do this using EF by creating a poco class for the result.
sing Microsoft.EntityFrameworkCore;
namespace myApp.Entities
{
[Keyless]
public class Result
{
public int Col1 { get; set; }
public int Col2 { get; set; }
....
public int Col20 { get; set; }
}
Then using FromSqlRaw in my PageModel:
Result= _db.MyEntity.FromSqlRaw($"exec MyStoredProcedure '{param}'").AsEnumerable().FirstOrDefault();
Then on my razor page, I can retrieve all the values by:
This works well, however having to create the Result class and list 20 columns for this one page feels excessive. I'm wondering if there's a better way to retrieve the values from the stored procedure without using EF.
Any recommendations are greatly appreciated.