您好,我无法理解为什么我收到错误消息,指出此SP期望@id,但在明确给出时却没有给出。这就是代码的样子
public Task<bool> InsertMessage(Message msg)
{
return CallDatabase(async (connection) =>
{
var affectedows = await connection.ExecuteAsync(
"messages_insert",
new
{
msg.Id,
msg.Group,
msg.GroupUserId,
msg.userId,
msg.StartTime,
msg.FinishTime
},
commandTimeout: 3600,
commandType: CommandType.StoredProcedure
);
return affectedows == 1;
});
}
这是数据库中的SP
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[messages_insert]') AND type in (N'P', N'PC'))
BEGIN
PRINT 'DROP PROCEDURE [dbo].[messages_insert]';
DROP PROCEDURE [dbo].[messages_insert];
END
GO
PRINT 'CREATE PROCEDURE [dbo].[messages_insert]';
GO
CREATE PROCEDURE [dbo].[messages_insert]
@id BIGINT, -
@group INT,
@group_user_id VARCHAR(100),
@user_id VARCHAR(100),
@start_time DATETIME,
@finish_time DATETIME
AS
BEGIN
INSERT INTO messages(id, group, group_user_id, user_id, start_time, finish_time)
VALUES(@id, @group, @group_user_id, @user_id, @start_time, @finish_time);
END
GO
我真的看不到我错了,并且堆栈跟踪真的什么也没说
Exception: System.Data.SqlClient.SqlException (0x80131904): Procedure or function 'messages_insert' expects parameter '@id', which was not supplied.
答案 0 :(得分:0)
在调用存储过程时,确保msg.Id不为null。