0
votes

Very basic scenario. I have a context attached to a db with one table that has one row in it. I can bind ui to the data and see data just fine, but changes, additions, etc do not save. Below is a 5 line bit that does not result in any changes to the db. Curious and confused.

        var context = new TestEntities();
        context .DataItems.Load();  // Testing - already one row in the table.
        context .DataItems.First().Data = "Blah Blah Blah";
        context .DataItems.Add(new DataItem() { Data = "Happy Birthday" });
        context .SaveChanges();

The data in the database does not change. No new row. No updated row.

Connection: <add name="TestEntities" connectionString="metadata=res:///DataModel.csdl|res:///DataModel.ssdl|res://*/DataModel.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="data source=|DataDirectory|\TestDB.sdf"" providerName="System.Data.EntityClient" />

I'm sure this is something stupid, but I don't see it.

1
Can you provide more details, any error/exception you are getting on this? You can use addTo_Object to add new records into the table.Surama Hotta
It's not something silly like your source database is begin copied every time you compile, overriding your changes, is it?Bob Vale
Nope, unfortunately not.user4013241
Got back to this after a day full of meetings. I changed the database to a server based database and it works fine. Something about the sdf db is horky. Any thoughts?user4013241

1 Answers

1
votes

try doing it as below:-

context .DataItems.AddObject(new DataItem() { Data = "Happy Birthday" });