10 Answers, 1 is accepted
In reverse-mapping scenarios you should set a field mapped to such a column as read-only. On transaction commit and opening a new one, we will fetch such a value. In forward mapping scenario, you should add your script to generate such a column and execute that post our DDL script execution (currently there is no easy and straight forward way of doing that for forward mapping).
Greetings,
Dimitar Kapitanov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I have tried setting the forward mapping to readonly, can you use a combination of both forward and reverse? The error I am getting now when I commit a new object is "Access to unfilled state field DateAuction.Model.User:userID stateField=16". I have the forward mapping for my userID set to readonly and it is a rowguid in the database.
You could set the field behavior manually. This can be done by adding behavior="readonly" to the field node inside the corresponding App.config file.
<
field
name
=
"name"
behavior
=
"readonly"
></
field
>
Field which is of type uniqueidentifier in the database cannot be auto incremented. Identity for field of this type cannot be set. You should place custom logic for this field when you insert new record:
userID = Guid.NewGuid();
I hope that will help you. Sincerely yours,
Damyan Bogoev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
As for the the auto incrementing I am aware of how the uniqueidentifier works. I have the userID set to a rowguid which does generate a new guid on an insert of a row. The field I am trying to increment is an int, I guess I would have to set both of those fields to be readonly in the app.config in order for the insert to work correctly?
The settings inside the App.config file are overwritten only when they are changed from the wizards. The field behavior would be overwritten if you change it from the Forward Mapping wizard.
Yes, you should set both of the fields as readonly in the App.config in order the insert to work correctly as well as you should set the integer field as identity.
Kind regards,Damyan Bogoev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Telerik.OpenAccess.Exceptions.DataStoreException: Error setting parameters on PreparedStatement for insert of '1573984092-de9c6ae2-937d-4415-860d-e5abf0a5c069':
System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.setObject(Int32 parameterIndex, Object x, Int32 targetSqlType, Int32 scale)
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.setObject(Int32 parameterIndex, Object x, Int32 targetSqlType, Int32 scale)
at OpenAccessRuntime.Relational.RelationalUtils.set_Renamed(PreparedStatement ps, Int32 index, Object val, Int32 javaTypeCode, Int32 jdbcType, RelationalColumn col)
at OpenAccessRuntime.Relational.RelationalGenericOID.setParams(PreparedStatement ps, Int32 firstParam, RelationalColumn[] pkc)
at OpenAccessRuntime.Relational.RelationalGenericState.setParams(PreparedStatement ps, Int32[] stateFieldNos, Int32 firstFieldNo, Int32 lastFieldNo, Int32 firstParam, PersistGraph pGraph, Int32 tableNo)
at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
I then added the readonly attribute to the autoinc column and got error like this:
2010-01-28 00:50:29,727 [ 21] ERROR ServiceErrorHandler - ProvideFault: Exception found.
Telerik.OpenAccess.OpenAccessException: Specified cast is not valid. ---> System.InvalidCastException: Specified cast is not valid.
at Telerik.OpenAccess.RT.StateManagerValueTypeWrapper.replacingGuidField(PersistenceCapable pc, Int32 field)
at Services.DataModel.Element.OpenAccessEnhancedReplaceField(Int32 )
at Services.DataModel.Element.OpenAccessEnhancedReplaceFields(Int32[] )
at OpenAccessRuntime.DataObjects.PCStateMan.replaceApplicationPKFields()
at OpenAccessRuntime.DataObjects.PCStateMan.commitImp(OpenAccessPersistenceManagerImp rpm)
at OpenAccessRuntime.DataObjects.LocalPMCache.doCommit(Boolean retainValues)
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.internalCommit(Boolean phase)
--- End of inner exception stack trace ---
at Telerik.OpenAccess.RT.ExceptionWrapper.Throw()
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x)
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.internalCommit(Boolean phase)
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.commit()
at OpenAccessRuntime.DataObjects.SynchronizedPMProxy.commit()
at Telerik.OpenAccess.RT.TransactionImpl.Commit()
If I remove the mapping for the autoinc column things work fine (but obviously I can't see Element_number in the entity, which I need).
You should set both the fields as readonly and provide additional logic to generate the guid value inside the insert method:
userID = Guid.NewGuid();
Because a column of type uniqueidentifier cannot be auto incremented.
Hope that helps.
Regards,
Damyan Bogoev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
A uniqueidentity can be autogen by marking it as a rowguid. This will cause it to generate a new guid on insert. This does works on MS Sql 2008.
I have a table that has 2 IDs, one is a guid that is also the primary key. This GUID is generated in code. This works fine. We also have another column in the table that is an int identity field (not associated with the PK in any way). This is auto generated by the DB. When we map the int identity column and try to write to the table is when we get the errors I described above. I have tried putting readonly on the fields, as I described in my post, but still get errors.
You could achieve this goal by doing the following steps:
1. Run the Forward Mapping wizard and click on the class node
2. On the right inside the Identity box select GUID as a Key Generator
3. Set the field behavior of the identity int field to readonly
When you finish click on the Done button.
You could use the attached solution as well.
I hope that helps.
Kind regards,
Damyan Bogoev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.