in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

[Db.SaveChanges(); Problem] Database will not get updated

Last post 02-07-2010 8:50 AM by Active_PHOENiX. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-05-2010 8:48 AM

    [Db.SaveChanges(); Problem] Database will not get updated

    Hello to all,

    I am encountering a problem while I update an entity fields and want to save it back to database. I am using Entity Framework as DAL and have designed a Repository to access the Entity objects.

    Database will show that a record has been saved but if I want to update the record it will not show the new data.

    InvoiceGeneratorEntities context = new InvoiceGeneratorEntities();

    var test = context.CompanyInformation.First();

    test.ContactName = "123"; context.AcceptAllChanges();

    context.SaveChanges(); //retrieve var test1 = context.CompanyInformation.First();

    MessageBox.Show(test1.ContactName);

    if we assume I have a CompanyInformation Entity the above code will not change its state.

    Do anybody get around such this problem before or is aware of the solution?

    Thanks in advance

    Filed under:
  • 02-06-2010 3:14 PM In reply to

    • jb42
    • Not Ranked
    • Joined on 02-04-2010
    • Posts 3

    Re: [Db.SaveChanges(); Problem] Database will not get updated

    The problem is not SQLite related, it's the AcceptAllChanges call. According to the documentation, AcceptAllChanges "Accepts the changes on all associated entries in the ObjectStateManager so their resultant state is either unchanged or detached. Basically you're undoing all changes so that SaveChanges has nothing to do. Normally, after invoking AcceptAllChanges followed by SaveChanges, the changes are visible in the entity (I checked that) but not in the database.

    B.T.W.: AcceptAllChanges has a really misleading name. Microsoft should change that ...

     

  • 02-07-2010 8:50 AM In reply to

    Re: [Db.SaveChanges(); Problem] Database will not get updated

    :) Thank you for feedback, It just solved my problem Thank A lot
Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems