是否可以使用实体框架执行存储过程,传入变量并返回数据以及返回值?
请不要留下任何关于实体框架的函数映射的代码。
我已经尝试过了,但我一直收到同样该死的错误:
过程或函数“usp_BusinessUser_Search”需要参数“@TotalRecords”,但未提供该参数。
这是我的代码:
SqlParameter Business = new SqlParameter("Business", Search.Term);
SqlParameter Location = new SqlParameter("Location", Search.Location);
SqlParameter PageNumber = new SqlParameter("PageNumber", Search.CurrentPage);
SqlParameter RecordsPerPage = new SqlParameter("RecordsPerPage", Search.RecordsPerPage);
SqlParameter TotalRecords = new SqlParameter("TotalRecords", 0);
SqlParameter parm = new SqlParameter()
{
ParameterName = "@TotalRecords",
Value = 0,
SqlDbType = SqlDbType.Int,
Direction = System.Data.ParameterDirection.Output
};
var List = db.ExecuteStoreQuery<ENT_SearchBusinessResult>("exec usp_BusinessUser_Search",Business,Location,PageNumber,RecordsPerPage,parm);
有谁知道是什么原因造成的?
谢谢
编辑:
存储过程代码:
ALTER PROCEDURE [dbo].[usp_BusinessUser_Search] ( @Business nVarChar(255) = NULL
, @Location nVarChar(255) = NULL
, @PageNumber Int = 1
, @RecordsPerPage Int = 10
, @TotalRecords Int OUTPUT)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SQL NVARCHAR(MAX)
, @CacheTable SYSNAME
, @TotalRows Int
, @Category VarChar(255)
, @BusinessCategory Int
, @TownCounty VarChar(50)
, @PcodeTownCounty VarChar(50)
INSERT Voucher_SearchHistory (Keyword, Location)
SELECT NULLIF(@Business,''), NULLIF(@Location,'')