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?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…