views:

182

answers:

1

I have a very simple table and I can happily query it using LINQ To SQL, but when I do any save/updates the GetChangeSet method on my datacontext is always empty.

My code is very simple (concatenated code from various classes):

    public static EntitiesDataContext EntitiesContext
    {
        get { return new EntitiesDataContext("Data Source=ANTSLAPTOP\\sqlexpress;Initial Catalog=nmncouk_d000;Integrated Security=True"); }
    }

    public static void Save(Price price)
    {
        EntitiesContext.Prices.InsertOnSubmit(price);
        EntitiesContext.SubmitChanges();
    }

    [Test]
    public void SavePrice()
    {
        Price price = new Price();
        price.Lower = 1;
        price.Upper = 2;
        price.PricePerDay = 10;
        Price.Save(price);
        Assert.AreNotEqual(price.PriceId, 0);
    }
+6  A: 

The problem is with your EntitiesDataContext method. Although it's static, it's returning a new DataContext on each call. So you are calling insertonsubmit and submitchanges against different contexts.

Adjust your save method to use the same context and all should be well.

Daniel M
Thanks yes I just worked that out myself!
tigermain