I have an application (ASP.NET 3.5) that allows users to restart a specific process if necessary. The process inserts records into the MS SQL table. I have an insert in Try / Catch and ignore catch if the entry already exists (error in Title will be valid). This worked fine using ADO, but after I got together in LINQ, I noticed an interesting thing. If there are already entries in the table when restarting the process, any new entries will be rejected with the same error, even though there is no existing entry. The code is as follows:
Dim ins = New tblOutstandingCompletion
With ins
.ControlID = rec.ControlID
.PersonID = rec.peopleID
.RequiredDate = rec.NextDue
.RiskNumber = 0
.recordType = "PC"
.TreatmentID = 0
End With
Try
ldb.tblOutstandingCompletions.InsertOnSubmit(ins)
ldb.SubmitChanges()
Catch ex As Exception
' An attempt to load a duplicate record will fail
End Try
The DataContext for the database was set during page load.
, DataContext :
ldb = New CaRMSDataContext(sessionHandler.connection.ToString)
Dim ins = New tblOutstandingCompletion
, , - . DataContext , .
James