none
Linq to SQL update query not updating Database RRS feed

  • Question

  • I'm quite new to Linq, mainly using it to query the database and insert records, but this is the first time I have attempted to update records. I have the following query that I am trying to use to lock a user account after too many log in attempts:

    Private Sub DoLock(ByVal Lock As Boolean)
    
        Using db As New DynamixDataContext
          Dim User As WEBMEMBER = (From Member In db.WEBMEMBERs _
                       Where Member.MEMNO = Me.MemNo _
                       Select Member).Single()
    
          If Lock Then
            'Linq lock query
            User.LOCKED = 1
          Else
            'Linq unlock query
            User.LOCKED = 0
          End If
    
          Try
            db.SubmitChanges()
          Catch ex As Exception
            Throw
          End Try
        End Using
    
      End Sub
    

    This runs happily with no errors, but no matter what I do, it does not update the database. I have tried rebuilding the data context, but that hasn't helped either.

    I have checked online, and from what I can tell my syntax is OK, but could be wrong.

    Anyone know what I'm doing wrong? I suspect I've missed off a silly little thing.

    Thanks,

    David

    Friday, August 6, 2010 12:01 PM

Answers

  • The most common cause of that is when no member of the entity class is marked as a PK member. If the table doesn't have a primary key you can just mark the column(s) that uniquely identify the records as primary key in the L2S designer. ( E.g. Member.MEMNO )


       Kristofer - Huagati Systems Co., Ltd.
    Cool tools for Linq-to-SQL and Entity Framework:
    huagati.com/dbmltools - add-in with new useful features for the L2S and EF designers in VS2008 and VS2010
    huagati.com/L2SProfiler - Query profiler for Linq-to-SQL, Entity Framework v4, and LLBLGen Pro
    • Marked as answer by dlewisQA Friday, August 6, 2010 1:16 PM
    Friday, August 6, 2010 12:07 PM
    Answerer

All replies

  • The most common cause of that is when no member of the entity class is marked as a PK member. If the table doesn't have a primary key you can just mark the column(s) that uniquely identify the records as primary key in the L2S designer. ( E.g. Member.MEMNO )


       Kristofer - Huagati Systems Co., Ltd.
    Cool tools for Linq-to-SQL and Entity Framework:
    huagati.com/dbmltools - add-in with new useful features for the L2S and EF designers in VS2008 and VS2010
    huagati.com/L2SProfiler - Query profiler for Linq-to-SQL, Entity Framework v4, and LLBLGen Pro
    • Marked as answer by dlewisQA Friday, August 6, 2010 1:16 PM
    Friday, August 6, 2010 12:07 PM
    Answerer
  • Thank you very much, that solved the problem. Strange that no primary key would cause that, but I guess it does make some sense really.

    Sadly I', having to work with a database with pretty much no structure, so will now have to spend some time looking at all of my tables.

    Friday, August 6, 2010 1:16 PM