I have a WPF app with a local .MDF file on which I created an Entity Framework class model.
Retrieving entities from the database works fine:
//get entities
using (var context = new TestDataEntities1())
{
var customers = from c in context.Customers
select c;
foreach (var customer in customers)
{
TheCustomers.Add(customer);
}
}
However, updating and adding and deleting* do not. There is **no error, the debugger steps right through, no messages in Output, but the data in the database table remains unchanged.
//update entity
using (var context = new TestDataEntities1())
{
var customer = (from c in context.Customers
where c.Id == 1
select c).FirstOrDefault();
customer.FirstName = DateTime.Now.ToString();
int num = context.SaveChanges(); //returns 1, table unchanged
}
//add entity
using (var context = new TestDataEntities1())
{
var customer = new Models.Customers();
customer.FirstName = "Ned";
customer.LastName = "Newton";
context.AddToCustomers(customer);
int num = context.SaveChanges(); //returns 1, table unchanged
}
//delete entity
using (var context = new TestDataEntities1())
{
var customer = (from c in context.Customers
where c.Id == 2
select c).FirstOrDefault();
context.Detach(customer); // table unchanged
}
What do I have to do to get Entity Framework to also update and add entities to the database table?