Returning Output Parameters with Dapper for .NET Core -


i'm struggling how map output parameters object using dapper, when create dynamicparamters template object.

var parameters = new dynamicparameters(entity); parameters.add("@id", dbtype: dbtype.int32, direction: parameterdirection.output); parameters.output(entity, x => x.id);               await conn.executeasync(    "todoiteminsert", entity,      commandtype: commandtype.storedprocedure);   

my hope above code map resulting id entity created parameters in first place. no matter try unable parameter return stored procedure. calling parameters.get<int>("@id") throws keynotfoundexception. parameters.get<int?>("@id") returns null.

my sql basic insert sproc

alter procedure [dbo].[todoiteminsert]     @name varchar(255)     , @description varchar(512)     , @duedate datetime = null     , @iscomplete bit = 0     , @id int output   insert     [todoitems] (     name     , description     , duedate     , iscomplete ) values (     @name     , @description     , @duedate     , @iscomplete )  set @id = scope_identity() 

what correct way output parameter dapper when trying use object template dynamicparameters?

figured out, didn't update code when moved template parameters. passing entity query, not parameters. once replaced rid of explicit addition of id output parameter. nicer!

var parameters = new dynamicparameters(entity); parameters.output(entity, x => x.id);               await conn.executeasync(    "todoiteminsert", parameters,      commandtype: commandtype.storedprocedure);   

Comments