2

I use this code to add one item to a SpareParts table in my database.

try
{
    Database1Entities _db = new Database1Entities();

    SparePart sparePart = new SparePart();
    sparePart.manufactureID = 2;
    sparePart.name = "detail";

    _db.SpareParts.AddObject(sparePart);

    int changesNumber = _db.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);

    int count = _db.SpareParts.Count();
    int i = 8 + 1;
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
}

I tried _db.SaveChanges(). That didn't help.

I don't get any exceptions. And if I start debug 4 times, I will see count = 4. And I can iterate through all my items. But if I wait 1 minute and start debugging one more time, I see count = 1. So it seems that my changes are still not in database.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Pelegrim
  • 77
  • 9

0 Answers0