1、示例存储过程SQL语句
CREATE PROCEDURE [dbo].[TodoItemInsert]
@Name VARCHAR(255)
, @Description VARCHAR(512)
, @DueDate DATETIME = NULL
, @IsComplete BIT = 0
, @Id INT OUTPUT
AS
INSERT INTO
[TodoItems]
(
Name
, Description
, DueDate
, IsComplete
)
VALUES
(
@Name
, @Description
, @DueDate
, @IsComplete
)
SET @Id = SCOPE_IDENTITY()
2、Dapper中执行存上面的储过程返回输出参数
var parameters = new DynamicParameters(entity);
parameters.Output(entity, x => x.Id);
await conn.ExecuteAsync(
"TodoItemInsert", parameters,
commandType: CommandType.StoredProcedure);