Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
171 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...