WP7 and Linq to SQL Issue

Topics: Bugs
Nov 28, 2011 at 12:12 AM

Hi, I'm having an issue with Linq to SQL that is very strange and i'm wondering if anyone else has had the same issue. Basically i have a Main Page and a Settings page. I navigate to the settings page and set a value that is stored in the linq to sql database. then when i hit back the same value is retrieved from the database during the view loaded event. The problem though is that the value retrieved is still the old value dispite the fact that i have called SubmitChanges on the settings page and the data context object should be completely new as i'm using the var keyword. The code looks like this

in the settings ViewModel it looks like this 


var dataContext = new DataContext(App.ConnectionString);
var settings = (from s in dataContext.Settings
                       select s).FirstOrDefault();

settings.EnableLocationService = this.EnableLocationService;

dataContext.SubmitChanges();

In the View loaded event it looks like this

var dataContext = new DataContext(App.ConnectionString);
var settings = (from s in dataContext.Settings
                       select s).FirstOrDefault();

if(settings.EnableLocationService)
{
// enable location service
}

 

I'm pulling my hair out trying to figure out how this is not working. I tried setting up a sample project without using Caliburn Micro and it works, so i'm guessing maybe caliburn his holding a reference somewhere. Is there something i'm missing? i though var would create and destroy the object when the method finishes executing.

Nov 28, 2011 at 8:41 AM

oddly i tried it again today and its working. I got no idea why.

Mar 13, 2013 at 11:38 PM
nitro52


Here is a database compatible with WinRT:
https://www.kellermansoftware.com/p-49-ninja-winrt-database.aspx