我通过带有App Service的Azure .NET后端中的SqlQuery
公开存储过程。但是当执行查询时,我收到此错误:
A member of the type, 'Id', does not have a corresponding column in the data reader with the same name
我不确定数据阅读器为什么试图引用/映射到Id
列,因为它不是我从sproc查询中选择的列的一部分。
这是我的代码:
//Creating the stored procedure
CREATE PROCEDURE IndividualAverages @AccountId nvarchar,@StartDate datetime,@EndDate datetime
AS
BEGIN
print 'SELECT DISTINCT AccountId,AlertDate,CreatedAt,UpdatedAt,Version,Deleted, (CAST(Consumed AS real) / Total - Pending) * 100 AS Percentage FROM dbo.Statistics WHERE AccountId = @AccountId AND AlertDate BETWEEN @StartDate AND @EndDate'
END
这是我的SqlQuery:
var paramId = new System.Data.SqlClient.SqlParameter("@userId", user_accountId.Trim());
var paramDateStart = new System.Data.SqlClient.SqlParameter("@StartDate",newStartDate.ToUniversalTime());
var paramDateEnd = new System.Data.SqlClient.SqlParameter("@EndDate", newEndDate.ToUniversalTime());
//This is where I execute the stored procedure
var userAverage = context.IndividualAverage.SqlQuery("EXEC dbo.IndividualAverages @userId,@StartDate,@EndDate" , paramId, paramDateStart, paramDateEnd).ToList();