blueshift
blueshift

Reputation: 881

DeleteOnSubmit: Records not deleted, no exception thrown

When I run the following code:

Public Function DeleteSessionItem(ByVal thisSessionItem As SessionItem) As Boolean
    Using db As New SEMDBDataContext(My.Settings.SEMDBConnectionString)
        db.DeferredLoadingEnabled = False
        If thisSessionItem.Modified IsNot Nothing Then
            db.Log = Console.Out
            db.SessionItems.Attach(thisSessionItem, True)
            db.SessionItems.DeleteOnSubmit(thisSessionItem)
            Try
                DeleteSessionItem = db.GetChangeSet.Deletes.Count > 0
                db.SubmitChanges()
            Catch ex As Exception
                DeleteSessionItem = False
            End Try
        End If
    End Using
End Function

No exceptions are thrown, the ChangeSet Deletes count is 1 and the SQL statements are:

DELETE FROM [dbo].[SessionItems] WHERE ([ItemID] = @p0) AND ([Modified] = @p1)
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [61]
-- @p1: Input Timestamp (Size = 8; Prec = 0; Scale = 0) [SqlBinary(8)]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1

SELECT NULL AS [EMPTY]
FROM [dbo].[SessionItems] AS [t0]
WHERE [t0].[ItemID] = @p0
-- @p0: Input BigInt (Size = 0; Prec = 0; Scale = 0) [61]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1

Yet the record is not deleted from the SessionItems table. This is a child table (of table Sessions) and SessionItems does not have a child table.

Any idea why the record is not being deleted?

Upvotes: 0

Views: 679

Answers (1)

blueshift
blueshift

Reputation: 881

While updating the DBML file, I must have accidentally dragged a table from a previous version of the database. I then had two connection strings in the project's list of settings. I was using the old connection string in the code above. Using the new connection string allows the code above to work.

Upvotes: 1

Related Questions