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 10-27-2010 2:14 AM by debrac. 4 replies.
Page 1 of 1 (5 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
    • Top 500 Contributor
    • Joined on 02-04-2010
    • Posts 6

    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
  • 07-13-2010 9:33 AM In reply to

    • Jbalzer
    • Top 200 Contributor
    • Joined on 09-23-2008
    • TOULOUSE (FRANCE)
    • Posts 8

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

    I'm having the same problem (using WPF Datagrid).  Can you tell us, please, how did you solve this problem?

    Thanks, 

     

  • 10-27-2010 2:14 AM In reply to

    • debrac
    • Top 500 Contributor
    • Joined on 10-20-2010
    • Posts 5

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

     Thanks for posting. I get info here.

    http://declutterdaytips.com/declutter-kitchen/
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems