Search code examples
c#entity-frameworkvisual-studiolocal-database

Local database not update after SaveChanges with entity framework


I would like to create a winform application using a local database (.mdf) and entity framework.

I'have created the database and the model. When I execute this code:

using (var context = new testEntity())
{
    CLIENTS c = new CLIENTS();
    c.Name = "name";
    c.Age = 10;
    context.CLIENTS.Add(c);
    context.SaveChanges();
}

a client is created in the database and I can get it with this code:

using (var context = new testEntity())
{
    List<CLIENTS> clients = context.CLIENTS.ToList();
    //break point here
}

But the added client is not on the .mdf file after closing the program. If I add some lines in the .mdf file, I can display them but not the opposite.

If someone can help me, thank you


Solution

  • check the Copy to Output Directory of DB.
    change the Copy to Output Directory property of the database file to Copy if newer..