use*_*933 4 c# sql sql-server stored-procedures entity-framework
我有一个 EF 代码优先模型。它工作正常,但是当我尝试使用Database.ExecuteSqlCommand它运行存储过程时,它总是返回 -1,我在存储过程中放入的内容无关紧要,结果始终为 -1
我的存储过程:
CREATE PROCEDURE [dbo].[Login_user]
@clientKey varchar(max)
AS
BEGIN
SET NOCOUNT ON
RETURN(0)
END
Run Code Online (Sandbox Code Playgroud)
我像这样运行它:
return Database.ExecuteSqlCommand(EXEC [dbo].[Login_user] {0}", key);
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
顺便说一句,如果我从 SQL Server Management Studio 运行存储过程,它会返回 0
USE [lo9iMed]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[Login_user]
@clientKey = N'76F41F99-EA9E-4181-A6FB-579D23D3C2C0'
SELECT 'Return Value' = @return_value
Run Code Online (Sandbox Code Playgroud)
提前致谢。
阿尼巴尔
因为您正在使用SELECT,所以您想要的是ExecuteScalar- 或者如果没有公开,则SqlQuery<int>. 如果您将其更改为 -您可能会得到您想要的结果return @return_value;- 但随后:您可能不会。
| 归档时间: |
|
| 查看次数: |
3873 次 |
| 最近记录: |