Duplicate Key Entry

Duplicate Key Entry

Postby Zero-G. » Wed 15 Dec 2010 10:29


I use your latest components of v6 mySQL dotConnect.
On the server, I have set a unique key, which goes over 5 fields.

When the user enters a duplicate article, then the error is thrown, as expectet.
But my question is: how can I remove this article from the Datacontext, so this input will not be tried again!?

Posts: 390
Joined: Sat 09 Dec 2006 12:20

Postby StanislavK » Thu 16 Dec 2010 16:36

As I can understand, you need to cancel changes made in DataContext so that the next call of SubmitChanges won't fail as well. Am I correct? For this purpose, please use the RejectChanges method:
Code: Select all
Dept newDept = new Dept() { Deptno = 10, Dname = "New Dept", Loc = "Somewhere" };
try {
catch(Exception ex)

Here we try to insert a new entity, and if SubmitChanges fails, we call RejectChanges to remove the problem entity from DataContext.

Please tell us if this helps.
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Return to LinqConnect (LINQ to SQL support)