This is a migrated thread and some comments may be shown as answers.

SavesChanges not working

1 Answer 29 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stephane
Top achievements
Rank 1
Stephane asked on 04 Aug 2012, 01:58 PM

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

1 Answer, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 06 Aug 2012, 07:16 AM
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
Tags
Getting Started
Asked by
Stephane
Top achievements
Rank 1
Answers by
IT-Als
Top achievements
Rank 1
Share this question
or