Main Page | Report this Page
.NET DotNet Forum Index  »  Visual C# Forum  »  LINQ and "Primary Key Violation"...
Page 1 of 1    

LINQ and "Primary Key Violation"...

Author Message
Paul...
Posted: Sun Nov 01, 2009 10:29 pm
Guest
Hi Everyone,
I am have a VS2008 multi-threaded application that process a list of
files by adding each file to a database. The directory names in one
table and file information in another. Since the threads are all doing
the same thing, only one could be he first to add a new directory. The
first add succeeds. Since the directory name is the key, the 2nd add
fails with an SQL exception (Primary Key Violation). I was expecting a
LINQ DuplicateKeyException, but I end up with an SQLException and all
subsequent LINQ operations in the datacontext fail. Any ideas?

Thanks,
Paul

VS2008 using SQL Express
 
Mr. Arnold...
Posted: Sun Nov 01, 2009 11:14 pm
Guest
Paul wrote:
Quote:
Hi Everyone,
I am have a VS2008 multi-threaded application that process a list of
files by adding each file to a database. The directory names in one
table and file information in another. Since the threads are all doing
the same thing, only one could be he first to add a new directory. The
first add succeeds. Since the directory name is the key, the 2nd add
fails with an SQL exception (Primary Key Violation). I was expecting a
LINQ DuplicateKeyException, but I end up with an SQLException and all
subsequent LINQ operations in the datacontext fail. Any ideas?


You check for the primary-key by querying for it before you do the add.

If the key exist, then you take another path to deal with the
duplication, otherwise, you do the add.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sat Dec 05, 2009 3:41 pm