Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

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

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?


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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...