Hi, I have an autoincrement column in my class and whenever I try and save the object, I get an 'Autoincrement' fields cannot be updated.
It is not a key so how can I set it to be readonlu.
The following code stops the error but the value of ID in a record I am selecting always shows 0. It should be showing 1833242
C#private int _ID;
[PersistentAlias("mID")]
public int ID
{
get { return _ID; }
set { SetPropertyValue("ID", ref _ID, value); }
}
What am I doing wrong?
Hi Mike,
Thanks for your question. I suggest that you map a private field to an auto-incremented column, and create a read-only non persistent property to retrieve a value. Please see the code below:
[Persistent("mID")] private int _ID; [PersistentAlias("_ID")] public int ID { get { return (int)EvaluateAlias("ID"); } }
I've created a sample project, which works fine for me. Please review it, and let me know whether this solution meets your requirements.
Thanks,
Uriah.
Hi Uriah,
The following code gives this error:
{"Schema needs to be updated. Contact your system administrator. Sql text: Error 7200: AQE Error: State = S0000; NativeError = 2121; [iAnywhere Solutions][Advantage SQL Engine]Column not found: mID -- Location of error in the SQL statement is: 11 AdsCommand query execution failed."}
private int _ID; [PersistentAlias("mID")] public int ID { get { return _ID; } set { SetPropertyValue("ID", ref _ID, value); } }
The following code works for display, but if I edit a row and then try and save the changes I get the following error:{"Executing Sql 'update "TCard" set "ID"=:p0,"CODE"=:p1,"JOB_NO"=:p2,"FM_NO"=:p3,"NOTE"=:p4,"DETAILS"=:p5,"DATE"=:p6,"USER_ID"=:p7,"TYPE"=:p8,"CUST_CODE"=:p1,"CALL_NUM"=:p9,"REP_CODE"=:p1,"STATUS"=:p1,"CREATED_TS"=:p10,"UPDATED_TS"=:p11,"OptimisticLockField"=:p12 where (("ROWID" = :p13) and ("OptimisticLockField" = :p14))' with parameters '{2342088},{},{01000022},{MA FORM},{test for crm},{{\rtf1\deff0{\fonttbl{\f0 Times New Roman;}}{\colortbl\red0\gree…},{15/03/2010 00:00:00},{MIKE},{C},{32088},{15/03/2010 16:11:26},{16/03/2010 12:26:57},{9},{9FQVWL_ASaKYVBgAfMFykQ},{8}' exception 'Advantage.Data.Provider.AdsException: Error 7200: AQE Error: State = HY000; NativeError = 5066; [iAnywhere Solutions][Advantage SQL][ASA] Error 5066: The requested operation is not legal for the given field type. AutoIncrement fields are read only. AdsCommand query execution failed.\r\n at Advantage.Data.Provider.AdsCommand.ExecuteStatement(IntPtr& hCursor, String& strIndex)\r\n at Advantage.Data.Provider.AdsCommand.ExecuteNonQuery()\r\n at DevExpress.Xpo.DB.ConnectionProviderSql.InternalExecSql(IDbCommand command)\r\n at DevExpress.Xpo.DB.ConnectionProviderSql.ExecSql(Query query)'"}
[Persistent("ID")] private int _ID; [PersistentAlias("_ID")] public int ID { get { return (int)EvaluateAlias("ID"); } }
The field in the table is called ID and is an auto increment field type. I am using Advantage Database Server V9.
Regards
Mike