Link Search Menu Expand Document

BulkImportIdentityBehavior


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 BinaryBulkInsert and BinaryBulkMerge operations. Pass the value to the identityBehavior argument when calling the operation.

For the BinaryBulkInsert operation:

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

For the BinaryBulkMerge operation:

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