I have the following stored procedure:
CREATE PROCEDURE [dbo].[usp_GetReportLevel]
AS
DECLARE @TEMP TABLE (BK_REPORT_LEVEL INT, REPORT_LEVEL_NAME VARCHAR(MAX))
INSERT INTO @temp
VALUES (0, 'Client Group'), (1, 'Client'), (2, 'Related Matter'), (3, 'Matter')
SELECT *
FROM @TEMP
GO
The entity database like this:
public IEnumerable<usp_GetReportLevel_Result> usp_GetReportLevel()
{
//const string storedProcedure = "usp_GetReportLevel";
var result = Database.SqlQuery<usp_GetReportLevel_Result>($"EXEC usp_GetReportLevel");
return result;
}
The usp_GetReportLevel_Result as this:
public class usp_GetReportLevel_Result
{
[Column("BK_REPORT_LEVEL")]
public int BK_REPORT_LEVEL;
[Column("REPORT_LEVEL_NAME")]
public string REPORT_LEVEL_NAME;
}
and the c# code in a constructor to select the list items from the stored procedure as this section:
List<SelectListItem> reportLevelList2= new List<SelectListItem>();
var reportLevelusp = context.usp_GetReportLevel();
foreach (var reportLevel in reportLevelusp)
{
SelectListItem lvl = new SelectListItem()
{
Text = reportLevel.REPORT_LEVEL_NAME,
Value = reportLevel.BK_REPORT_LEVEL.ToString()
};
reportLevelList2.Add(lvl);
}
ReportLevelList = reportLevelList2;
Now if I debug that code, the foreach will enter 4 times, telling me that it is reading the database values right, but the values BK_REPORT_LEVEL and REPORT_LEVEL_NAME are always 0 and null respectively.
Why is this happening? The stored procedure is returning what I want to expect if I execute it on the database, Why Linq isn't getting the correct data? I can't see the error

SET NOCOUNT ONto the start of your procedure, does that help?INSERTbut after theAS?ASand after theDECLARE @TEMP TABLE, neither worked