I have entity structure like this:

base class EntityBase with Key field Id (type of long) child classes: Person and Material both are inherited from EntityBase

i have copied sql database from one pc to another (by sql export procedure) and as a result (after some time program work and creates some entities) i have a situation when dbo.Person and dbo.Material tables contains rows with same Id 1921. Now when i'm trying to query for Session.Query.Single<person>(1921) - this code throws exception:

Entity with Key = 'Material (unknown), (1921)' does not exist.

stacktrace:

Xtensive.Orm.QueryEndpoint.Single(Key key)
Xtensive.Orm.QueryEndpoint.Single[T](Object[] keyValues)
Teleavtomatika.Practices.DataObjects.DtoBase`1.GetEntity() 
Teleavtomatika.Practices.DataObjects.DtoBase`1.Teleavtomatika.Practices.DataObjects.IDtoBase.GetEntity() 
Teleavtomatika.Practices.DataObjects.DtoBase`1.TransferDataToEntity(T entity, HashSet`1 cache) 
Teleavtomatika.Practices.DataObjects.DtoSet`1.Merge[TEntity,TDto](EntitySet`1 entitySet, DtoSet`1 dtoSet, HashSet`1 cache)

So my question is: where does DO stores information about last Key (ID) generated and how can i eliminate the situation when two different types of entities inherited from the same base entity class can have same Id?

My DO version is 4.5.5.

asked Apr 27 '15 at 01:48

Dmitry%20F's gravatar image

Dmitry F
11669

edited Apr 27 '15 at 01:53


One Answer:

Hello Dmitry F.

According to key providing behavior keys of two entity can't be the same. I thing something went wrong when you did export procedure. Generally, keys are generated by special table in database which name is <name of="" keys'="" type="">-Generator or some custom name for custom generators. It have only one field with auto increment. Sometimes if DBMS supports sequences then DO use it. As I know, DO uses sequences for MS SQL Server 2012 and PostgreSql and Oracle. I suppose something happened with generator table or sequence.

You can define key generator parameters in domain configuration.

Using AppConfig in <domain> element:


<keyGenerators>
 <!-- Seed and cache size values are just for example -->
      <keyGenerator name="Int32" database="main" seed="128" cacheSize="128"/>
</keyGenerators>

or using DomainConfiguration.KeyGenerators collection


//Cache size and seed values are just for example.
domainConfiguration.KeyGenerators.Add(new KeyGeneratorConfiguration("Int32") {CacheSize = 128, Seed = 128});//for Int32 keys
domainConfiguration.KeyGenerators.Add(new KeyGeneratorConfiguration("Int64") {CacheSize = 128, Seed = 128000});// for Int64 (long) keys

answered Apr 27 '15 at 04:21

Alexey%20Kulakov's gravatar image

Alexey Kulakov
71715

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×12
×8
×3

Asked: Apr 27 '15 at 01:48

Seen: 4,538 times

Last updated: Apr 27 '15 at 04:21

powered by OSQA