Sources/Object/Publish-Object.ps1

using namespace Belin.Sql
using namespace System.Data

<#
.SYNOPSIS
    Inserts the specified entity.
.INPUTS
    The entity to insert.
.OUTPUTS
    The generated primary key value.
#>

function Publish-Object {
    [CmdletBinding()]
    [OutputType([long])]
    param (
        # The connection to the data source.
        [Parameter(Mandatory, Position = 0)]
        [IDbConnection] $Connection,

        # The entity to insert.
        [Parameter(Mandatory, Position = 1, ValueFromPipeline)]
        [object] $InputObject,

        # An optional command builder used to build the SQL query to be executed.
        [SqlCommandBuilder] $Builder,

        # The wait time, in seconds, before terminating the attempt to execute the command and generating an error.
        [ValidateRange("NonNegative")]
        [int] $Timeout = 30,

        # The transaction within which the command executes.
        [IDbTransaction] $Transaction
    )

    begin { $Builder ??= New-CommandBuilder $Connection }
    process { [DbConnectionExtensions]::Insert($Connection, $InputObject, $Timeout, $Transaction, $Builder) }
}