Answered Debug some code

  • Wednesday, January 02, 2013 12:22 PM
     
     

    I have a largish project that im attempting to work out why updates are not saved although new items are saved. I noticed when updating the following code is hit:

        Public Sub SaveCust(ByVal c As Cust)
            If c.Id = 0 Then
                DataContext.Custs.InsertOnSubmit(c)
            End If
            SaveAmendments()
        End Sub

        Public Sub SaveAmendments()
            DataContext.SubmitChanges()
        End Sub

    When its an update the If c.ID = 0 line does NOT hit which makes sense as its not a new record but the code goes onto SaveAmendments. Following this i noticed this code being hit:

    Private Sub DataContext_OnChanged(ByVal changeSet As System.Data.Linq.ChangeSet) Handles _DataContext.OnChanged

            GenerateAuditRecords(changeSet.Inserts, AuditType.Insert)
            GenerateAuditRecords(changeSet.Updates, AuditType.Update)
            GenerateAuditRecords(changeSet.Deletes, AuditType.Delete)

        End Sub

    BUT the Updates line (second line) is set to 0 (as in nothing to update i would have thought). So this means somewhere its not doing what its supposed to do. Does anyone have any ideas of how i could troubleshoot this further to see whats causing this? 

    Thanks

All Replies

  • Wednesday, January 02, 2013 6:55 PM
     
     
      

    Can you show the code that gets executed before calling SaveCust.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

  • Thursday, January 03, 2013 9:13 AM
     
     

    From the top of my head the calling code is:

    Dim Cust = cst.Customers.FirstOrDefault(Function(c) c.Id = id)

    cust.CustomeComId = txtComID.Text
    custsvc.SaveCustomer(cust)
    custsvc.SaveAmendments()

    There are a couple of lines that may be related to the Cust instance but if you require that ill post it, if the above is not enough to play by?

    Thanks

  • Thursday, January 03, 2013 4:03 PM
     
     Answered
    Hi Pure Deal;

    It is hard to say what is going on without seeing the lines of code that are being executed before the call to SaveCust. Also make sure you are using the same DataContext to execute the query and to save the modified result. Can you post the actual code seeming some things don't look right with the last post.

      

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked As Answer by Pure Deal Friday, January 04, 2013 7:32 PM
    •