Link Search Menu Expand Document

PostgreSqlBulkImportIdentityBehavior


This enum was previously named BulkImportIdentityBehavior. That name is now deprecated in favor of PostgreSqlBulkImportIdentityBehavior and will be tagged starting v1.16.0 of the RepoDb.PostgreSql and RepoDb.PostgreSql.BulkOperations packages.

This enum defines the behavior of the identity property/column when an entity is bulk-imported into a target table. It applies only to the PostgreSQL RDBMS.

Enum Values

NameDescription
KeepIdentityA value that indicates whether the value of the identity property/column will be kept and used.
ReturnIdentityA value that indicates whether the newly generated identity value from the target table will be set back to the entity.
UnspecifiedNo action is required. (This is the default value)

Usability

This enum is used by both the BulkInsert and BulkMerge operations. Pass the value to the identityBehavior argument when calling the operation.

For the BulkInsert operation:

using (var connection = new NpgsqlConnection(connectionString))
{
    var people = GetPeople(1000);
    var insertedRows = connection.BulkInsert(people,
        identityBehavior: PostgreSqlBulkImportIdentityBehavior.ReturnIdentity);
}

For the BulkMerge operation:

using (var connection = new NpgsqlConnection(connectionString))
{
    var people = GetPeople(1000);
    var mergedRows = connection.BulkMerge(people,
        identityBehavior: PostgreSqlBulkImportIdentityBehavior.ReturnIdentity);
}