SavesChanges not working

2 posts, 0 answers
  1. Stephane
    Stephane avatar
    1 posts
    Member since:
    Aug 2012

    Posted 04 Aug 2012 Link to this post


    Hi guys,

      I just started to use OpenAccess ORM and i like. Very easy to install and configure.

    However, i am running into an issue [i have been on it for the last 3 hours] and can't figured it. I trying to simply update some customer details in my BLL using the following:

     public void UpdateCustomer(CTeasy.Customer customer)
            {
                using (CTeasy.EntitiesModel dbContext = new CTeasy.EntitiesModel())
                {
                    Customer customerToUpdate = this.GetCustomerByID(customer.CustomerID);
                    customerToUpdate.AddressLine1 = customer.AddressLine1;
                    customerToUpdate.AddressLine2 = customer.AddressLine2;
                    customerToUpdate.ZipCode = customer.ZipCode;
                    customerToUpdate.City = customer.City;

                    // GetChanges
                    Telerik.OpenAccess.ContextChanges contextChanges = dbContext.GetChanges();

                    dbContext.SaveChanges();
                }
            }

    I am able to successfully retrieve the customer to update using the same DB context within the GetCustomerByID method so my setup is correct.

    However, the SaveChanges() method is not "doing" anything in my case not even throwing an exception. 

    I checked with SQL Profiler and don't even see an sql update statement being executed,

    Any idea?

    Regards

  2. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 06 Aug 2012 Link to this post

    Hi Stephane,

    How is the customer retrieved in this line:

    Customer customerToUpdate = this.GetCustomerByID(customer.CustomerID);

    Be aware that you must fetch the customer with the same instance of the Context (which you construct in the using statement). Otherwise OpenAccess will not know that any changes has been done to the object and thus not perform any actions on save.

    Since you construct the Context within the using statement I do not think that it is the same instance you use for fetch in the above method. Maybe you could pass the Context created to the GetCustomerById method or by other means use the exact same Context for fetch and save.

    Regards

    Henrik
  3. DevCraft banner
Back to Top