Mysql "Update" trouble

Aug 5, 2011 at 7:25 AM

Hi everybody,

I'm trying this beautiful framework with the Mysql storage provider, i'm having some troube with auto increment on update.

When i want to persist an object that exists for example with "ID = 1" it create a new object with a new id, so i can't update !

So i've looked the object attributes in debugger mode and everything seems fine..

Anyone had an idea ?

Thank you.

Oct 25, 2011 at 1:05 PM

Clem,

Please verify if you are using the correct method to update an existing item on your database. The way to create a new item is a different way to update, but is the same way to persist changes. Take a look...

If you want to create (insert) a new item on database, you will create a new object and persist its on database:

 

Example:

Person person = new Person();

person.Name = "Name";

person.LastName = "Last Name";

...

context.PersistChange(person);

 

If you want to update an existing item, you must get this object from database, do your necessaries updates on object properties and persist its changes on the same object... something like this:

Person person = context.GetObject<Person>("PID={0}, SOMEID);

person.Name = "Correct name";

person.LastMane = "Correct last name";

....

context.PersistChange(person);

 

Basicaly: if you want to update an object, you must use GetObject<T>, make your updates and persists changes. If you want to insert a new item on database, you need to instantiate a new object, populate its propertiens and persist its changes.