views:

360

answers:

2

I'm experiencing an odd scenario and I'm looking for ways to figure out what's going wrong. I've got a piece of code that inserts a row into a table - the kind of thing I've done in dozens of other apps - but the end result is nothing happens on the database end, and no errors are generated. How do I find out what's going wrong?

Here's my code:

Partial Class MyDatabaseDataContext

    Public Sub CreateEnrollee(subId, depId)

        dim newEnrollee = New enrolee With {.subId = subId, .depId = depId}

        Me.enrollees.InsertOnSubmit(newEnrollee)
        Me.SubmitChanges()

        dim test = NewEnrollee.id '<-- auto-incrementing key'

    End Sub

End Class

After SubmitChanges is called, no new row is created, and "test" is zero. No errors are generated. I have no idea why it's not trying to insert the row. Any ideas on how to debug this?

+1  A: 

You could enable logging:

Me.Log = Console.Out;


You could check the ChangeSet for your object.

David B
I did, but it doesn't show any statements, like the Data Context determined an insert wasn't necessary or possible or something. (The logging does show a SELECT statement earlier in my code so I know it's working.)
gfrizzle
+1  A: 

FOUND IT! Part of the debugging I did for some other issues included adding some logging to some of the extensibility methods:

Partial Private Sub InsertEnrollee(instance As Enrollee)
End Sub

I thought "InsertEnrollee" existed so I could perform actions after the Enrollee was inserted, so I added logging code here and that's when the trouble started. Now I'm guessing this is how you would override the Enrollee insert and do it yourself if you so desired. Since I was essentially overriding with logging code, that's why nothing was happening (from a database perspective).

gfrizzle
I've just had this exact problem, and for the life of me couldn't work out what was stopping the inserts!As it turns out, this behaviour occurs even if there's no implementation in your partial method stub.
Dan