1

I'm having a problem updating an item using Linq to SQL in WP8. When I run the code, the Object gets updated fine when going trough the app. However, as soon as I leave the app, the update gets lost.

It seems that .SubmitChanges() does not work. What could be the reason?

Public Sub AdjustTile(ByVal thisTile As TileObject, ByVal info As Integer)

        Dim query = From row As TileObject In tileDb.TileTable
                    Where row.id = thisTile.id
                    Select row

        For Each row As TileObject In query
                row.ChoosenWide = info
        Next

        tileDb.SubmitChanges()

End sub

The functions InsertOnSubmit and DeleteOnSubmit work fine...

Misja
  • 91
  • 1
  • 6
  • it is possible you are coding against the wrong dbcontext obj. – alsafoo Mar 30 '14 at 21:55
  • You should not be using a persistent DataContext anyway. Certainly you should not access the database from a phone app because this offers zero security. Anyone can connect to your DB and alter it. – usr Mar 30 '14 at 22:03
  • @alsafoo: if this is true, then how is it possible that InserOnSubmit works? This app uses a local database which will only be used by the user. Also, it only contains simple settings like what the choosen tilestyle is. If I add a new datacontext, such as Using db As New TileDataContext("Data Source=isostore:/Tiles.sdf") – Misja Mar 31 '14 at 11:41
  • it still does not work. Then the app, which updates now, doesn't update anymore neither. – Misja Mar 31 '14 at 11:52
  • i have for you two things to check:- 1) Check if you are inserting and submitting to the same data context. 2) Make sure you are not disposing your data context object before reaching your method which submit changes. – alsafoo Mar 31 '14 at 15:35

1 Answers1

0

Ok, I figured out my newbie mistake. Turns out, I forgot to add:

NotifyPropertyChanging("ChoosenWide") and NotifyPropertyChanged("ChoosenWide")

See http://code.msdn.microsoft.com/wpapps/Local-Database-Sample-57b1614c

Thanks alsafoo & usr for your help.

    Private _ChoosenWide As Integer
    <Column()>
    Public Property ChoosenWide() As Integer
        Get
            Return _ChoosenWide
        End Get
        Set(ByVal value As Integer)
            If _ChoosenWide <> value Then
                NotifyPropertyChanging("ChoosenWide")
                _ChoosenWide = value
                NotifyPropertyChanged("ChoosenWide")
            End If
        End Set
    End Property
Misja
  • 91
  • 1
  • 6