Entity Framework Extensions: Can't BulkMerge entities with empty identity property

370 views Asked by At

I uses BulkMerge method of Entity Framework Extensions for insert/update large collections of entities. Entity table have identity column Id that used as a primary key. When I try to BulkMerge collection with several newly created entities (they have Id = 0 by default) it throws such exception: Violation of PRIMARY KEY constraint 'PK_Users'. Cannot insert duplicate key in object 'dbo.Users'. The duplicate key value is (0). Btw, BulkInsert method with same entities works fine. I tried to use options like AutoMapOutputDirection, InsertIfNotExists or MergeKeepIdentity but they were ineffective. Can anyone suggest the correct options for proper BulkMerge work or any other ways to solve issue?

0

There are 0 answers