The problem is in first insertion, it will call BulkInsertEntitiesAsync:
/// <returns>A task that represents the asynchronous operation</returns>
protected virtual async Task InsertInstallationDataAsync<T>(params T[] entities) where T : BaseEntity
{
await _dataProvider.BulkInsertEntitiesAsync(entities);
}
public override async Task BulkInsertEntitiesAsync<TEntity>(IEnumerable<TEntity> entities)
{
using var dataContext = CreateDataConnection(LinqToDbDataProvider);
await dataContext.BulkCopyAsync(new BulkCopyOptions() { KeepIdentity = true }, entities.RetrieveIdentity(dataContext));
}
>
> and for second insertion, it calls InsertEntityAsync:
>
> ```c#
> protected virtual async Task<T> InsertInstallationDataAsync<T>(T entity) where T : BaseEntity
> {
> return await _dataProvider.InsertEntityAsync(entity);
> }
> ```
>
> There is a minor difference in call these two methods, in BulkInsertEntitiesAsync, it will RetrieveIdentity (so count the largest id from table, and use that for the start id of all bulk insert entities), this will not affect the current value of Product_Picture_Mapping_Id_seq, after inserted two ProductPicture records, the current value for Product_Picture_Mapping_Id_seq is still 0.
>
> And then it try to insert a ProductPicture with InsertEntityAsync, this time, it will use the current sequence id from Product_Picture_Mapping_Id_seq, so we will get allocated id = 1, but this id already existed in ProductPicture table, so you will get an error:
>
> duplicate key value violates unique constraint "PK_Product_Picture_Mapping"
Source: https://www.nopcommerce.com/en/boards/topic/101149/is-postgres-database-supported-in-nopcommerce
nopCommerce version: develop
}