public Task <int> InsertTicket(Ticket newTicket) { string query = @"insert into dbo.Ticket(Name,IssuerUserId,DateCreated,DeadLine,StatusId) values (@Name, @IssuerUserId, @DateCreated, @DeadLine, @StatusId); select @Id = @@IDENTITY"; var p = new DynamicParameters(); p.Add("@Name", value: newTicket.Name); p.Add("@IssuerUserId", value: newTicket.IssuerUserId); p.Add("@DateCreated", value: newTicket.DateCreated, dbType: DbType.DateTime); p.Add("@DeadLine", value: newTicket.DeadLine, dbType: DbType.DateTime); p.Add("@StatusId", value: newTicket.StatusId); p.Add("@Id", 0, DbType.Int32, ParameterDirection.Output); SqlMapper.Execute(_connectionFactory.GetConnection, query, p); _connectionFactory.CommitAsync(); return(Task.FromResult(p.Get <int>("@Id"))); }