By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,811 Members | 785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,811 IT Pros & Developers. It's quick & easy.

error : DuplicateKeyException when trying to delete / update arecord. bug in LINQ?

P: n/a


Hi,

I'm using LINQ.. and I would like to understand if it's a bug or not
in LINQ...

I've a situation like: I'm reading all records via "Select" Statement
and a specific select statment #1 record retrieves the record and
propose for Delete or Update... when I make changes and click on
Update I get "DuplicateKeyException Cannot add an entity with a key
that is already in use. "

I googled and I found the following statement " ...when you use the
same DataContext for CUD as it does for Select. As a result, if a
Select is performed before an Update or Delete then the Update or
Delete will fail. This is because the data objects are already loaded
in the DataContext's cache from the previous query, so the Attach call
made by LDS is not valid.

This will be fixed so that LDS uses separate DataContexts for CUD
operations in the next release.

So my question is: Did someone have had the same situation?
objDataContext = DatabaseFactory.GetLinq();
objDataContext.F4102s.Attach(LocalTable); ---it
DUMPS HERE....
objDataContext.Refresh(RefreshMode.KeepCurrentValu es,
LocalTable);

objDataContext.SubmitChanges(ConflictMode.Continue OnConflict);

see link below for the the statement....
http://forums.asp.net/t/1203078.aspx
any idea how I can avoid duplicate key error when I do Updates)
-mesut
Sep 23 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.