我有asp.net的MVC 4項目中,嘗試調用T-SQL,我需要選擇一些行與並非所有列問題在asp.net mvc的SP
CREATE PROCEDURE [dbo].[SP_name]
@iSkip int, @iTake int
AS
BEGIN
SELECT [Column1], [Column2], [Column3] FROM [dbo].[Table] WITH(NOLOCK)
ORDER BY
[Column1] DESC
OFFSET @iSkip ROWS
FETCH NEXT @iTake ROWS ONLY
END
但是,當我嘗試調用該SP從代碼中我有以下錯誤
The data reader is incompatible with the specified 'Model.Table'. A member of the type, 'Column4', does not have a corresponding column in the data reader with the same name.
當我試圖把這種對MS SQL工作室一切正常,沒有任何人知道哪裏是我的錯?我該怎麼做?
編輯:
這是庫:
public IEnumerable<T> GetAllEntitiesWithParam(string procedureName, int param1, int param2) {
return _context.DbContext.Database.SqlQuery<T>("EXEC " + procedureName + " @param1, @param2", new SqlParameter("param1", param1), new SqlParameter("param2", param2));
}
這裏是內部代碼:
IEnumerable<Table> list = _myRepo.GetAllEntitiesWithParam("SP_name", par1, par2);
您將需要顯示用於調用存儲過程的代碼。 – Paddy
@Paddy更新我的問題 – BorHunter
它說'Column4'不存在。更新你的查詢並在選擇中添加'[Column4]',並檢查 – Bharadwaj