This project is read-only.

AutoIncrement issue

Apr 7, 2010 at 10:46 PM

Dear Christian,

first, thank you for grat work done. I have been evaluating several ORMs, but this one is exactly like I want it to have. Now my problem:

I am using MySql and it is written in the code documentation to FieldAttribute.cs, that AutoNumber is only supported for Access and MsSql - but on the other hand MySqlStorage seem to work with it also. But in my test case the id field value is not updated (I am inserting the object by using ObjectContext.PersistChanges<Type>(instance)).

My questions are:

1) is AutoNumber supported for MySql?

2) am I right when inserting new object by using PersistChanges<T>() method? (in the documentation I haven't found example for inserts, only for update)

3) am I right when I expect, that when I pass an object to the ObjectContext to be persisted, the ID field marked as AutoNumber will be updated after the insert?


Thank You!



Apr 8, 2010 at 11:34 PM
Edited Apr 8, 2010 at 11:34 PM

1) Should be, I see no reason why not. I'll have to try it when I get home

2) Yes the PersistChanges method handles inserts, updates and deletes

3) Yes using PersistChanges will automatically update your Id field after an insert

Apr 9, 2010 at 4:00 AM


1) yes. It is using the LAST_INSERT_ID() function to get the ID, if an autoincrement is specified. Have you tried debugging into it?


Apr 11, 2010 at 10:43 PM


so I have debugged and found out, that AutoNumber works fine, I was just having the setter done badly for the ID. My current problem is, that I am having following situation:

I get the object A via web service.

I set the A.MyUser  manually - and here is the problem - I use ObjectHolder for the MyUser property and since the object A came from web service and not from ObjectContext, it had the ObjectHolder for the MyUser set to null - I have created ObjectHolder manually, but it is evidently wrong since it does not get the ref to ObjectContext. 

Is there some way to manually create the ObjectHolder correctly?