gpt4 book ai didi

c# - Entity Framework : how do I run a stored procedure and return a value?

转载 作者:行者123 更新时间:2023-11-30 14:35:41 27 4
gpt4 key购买 nike

是否可以使用 Entity Framework 执行存储过程,传入变量并返回数据和返回值?

请不要留下任何关于 Entity Framework 函数映射的代码。

我已经试过了,但我一直收到同样该死的错误:

Procedure or function 'usp_BusinessUser_Search' expects parameter '@TotalRecords', which was not supplied.

这是我的代码:

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,'')

最佳答案

关于c# - Entity Framework : how do I run a stored procedure and return a value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11779155/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com