DeleteOnSubmit: registros no eliminados, no se lanzó ninguna excepción

Cuando ejecuto el siguiente código:

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?

preguntado el 08 de noviembre de 11 a las 17:11

1 Respuestas

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.

respondido 09 nov., 11:23

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.