This question is locked. New answers and comments are not allowed.
Hi,
I'm using ORM 2013.1 and Firebird 2.5.2, and using code-only mapping.
I set an Id with type long, and using KeyGenerator.HighLow with the code below.
If I insert two objects and call SaveChanges, it will raise an exception on the second insert.
The database was able to create the voa_keygen table. Even using a different KeyGenerator like Guid will not work, except for Autoinc which seems to be working.
Any ideas how to solve this problem?
I'm using ORM 2013.1 and Firebird 2.5.2, and using code-only mapping.
I set an Id with type long, and using KeyGenerator.HighLow with the code below.
mappingConfiguration.HasProperty(objMap => objMap.Id).IsIdentity(KeyGenerator.HighLow);
If I insert two objects and call SaveChanges, it will raise an exception on the second insert.
Instance of
'class name here'
with identity
'60283631--1'
already exists
in
the cache of the
object
scope.
The database was able to create the voa_keygen table. Even using a different KeyGenerator like Guid will not work, except for Autoinc which seems to be working.
Any ideas how to solve this problem?
6 Answers, 1 is accepted
0
Hi Dennis,
Damyan Bogoev
the Telerik team
I was unable to reproduce the wrong behavior on my side. I have tested the problem against OpenAccess ORM Q1 2013. Please find the test application attached to my answer.
Damyan Bogoev
the Telerik team
Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
0
Dennis
Top achievements
Rank 1
answered on 29 Mar 2013, 01:53 AM
Hi Damyan,
I checked your code and it is almost similar to mine so I was curious why your code is working and mine is not. It turns out it has something to do with assigning the identify field "Id" to "-1". In my constructor, I initialized all Id's to -1 and this is causing the problem. I've modified your code and did the same and it causes the duplicate key exception.
The reason I'm using the "-1" value is to check if my object has been added in the DB or not.
1. Will OA use negative numbers as identity?
2. What is the best way to check if my object has been persisted or not? I can query the DB or add a new variable but maybe you have a better solution.
Thanks!
- Dennis
I checked your code and it is almost similar to mine so I was curious why your code is working and mine is not. It turns out it has something to do with assigning the identify field "Id" to "-1". In my constructor, I initialized all Id's to -1 and this is causing the problem. I've modified your code and did the same and it causes the duplicate key exception.
The reason I'm using the "-1" value is to check if my object has been added in the DB or not.
1. Will OA use negative numbers as identity?
2. What is the best way to check if my object has been persisted or not? I can query the DB or add a new variable but maybe you have a better solution.
Thanks!
- Dennis
0
Hi Dennis,
Actually this is expected behavior when a Highlow Key Generator is being used for a given persistence capable type. If you assign the identity member with a value different than 0 it will be used for persisting the corresponding entity to the database.
You could use the following approach to obtain the state for the provided entity instance:
Hope that helps.
Regards,
Damyan Bogoev
the Telerik team
Actually this is expected behavior when a Highlow Key Generator is being used for a given persistence capable type. If you assign the identity member with a value different than 0 it will be used for persisting the corresponding entity to the database.
You could use the following approach to obtain the state for the provided entity instance:
ObjectState state = OpenAccessContext.PersistenceState.GetState(entity);
Hope that helps.
Regards,
Damyan Bogoev
the Telerik team
Free Webinar: OpenAccess Integration in Sitefinity. SIGN UP NOW.
0
Dennis
Top achievements
Rank 1
answered on 29 Mar 2013, 09:27 AM
Hi Damyan,
Thank you for the answer. Got what I needed.
One more thing, I mentioned I used 'long' as the type for my 'Id' but voa_keygen table uses 'int'. Is there a way to change the data type from 'int' to 'long'? or even use unsigned or negative numbers?
Also, it is possible to have unused numbers in between grabs so what will happen if it cannot grab the range of number specified? Ex. 'last_used_id' is already near the max value of 'int' and it cannot grab 10 more numbers.
- Dennis
Thank you for the answer. Got what I needed.
One more thing, I mentioned I used 'long' as the type for my 'Id' but voa_keygen table uses 'int'. Is there a way to change the data type from 'int' to 'long'? or even use unsigned or negative numbers?
Also, it is possible to have unused numbers in between grabs so what will happen if it cannot grab the range of number specified? Ex. 'last_used_id' is already near the max value of 'int' and it cannot grab 10 more numbers.
- Dennis
0
Dennis
Top achievements
Rank 1
answered on 03 Apr 2013, 02:04 AM
Hi, Anyone can help me with the voa_keygen on how to convert it to long?
As for the last_used_id being all used up (Int32.MaxValue), I tested it and it will cause a DataStoreException.
- Dennis
As for the last_used_id being all used up (Int32.MaxValue), I tested it and it will cause a DataStoreException.
- Dennis
0