In most cases, the developer is not required to use directly primary keys, all keys must be done secretly. However, you can learn (and change) the primary key value of the data object. It is necessary to cause the data object property __PrimaryKey
.
the Generator of primary keys
The primary keys of the objects generated by the method ICSSoft.STORMNET.KeyGen.KeyGenerator.Generate
. Flexberry ORM does not know which generator is used and what is the type of the primary key. Specific generator written in the object class data attribute KeyGeneratorAttribute
.
The generator can be of two types:
- Return keys, unique brand.
- Return keys, unique within the workstation.
If the generator of the second type, it must implement the method Unique
return false
, otherwise true
.
The reason for the existence of this method is the following: if the generator of the second type, service data to replace the primary key on a completely unique, verify with the General (clientoptions) a key generator implemented in a service.
This feature is the optimization, because that’s absolutely unique keys can be complex to generate, and long, and the constant reconciliation of General generator low.
Currently implemented generator ICSSoft.STORMNET.KeyGen.GUIDGenerator
that returns the longest key of the first type. This generator is used by default, the prescribed attribute KeyGeneratorAttribute
directly to the class DataObject
.
The developer can see the type of the key generator for a particular class the data by calling Information.GetKeyGeneratorType
.
change the type and rules of the generation of primary key
If necessary, the developer can change the type of the primary key and the law of its generation, because the primary key in the Flexberry ORM can be of any type.It is important that the primary key type supported the following:
- Method
ToString()
to convert to a string, and a static method Parse(string) for the reverse receipt from the row key. - To implement the interface
System.IСomparable
. - Support implicit (imlicit) convert to string and back.
- Support implicit (imlicit) conversion to the target type store and back.
All the key generators must inherit from the abstract class ICSSoft.STORMNET.KeyGen.BaseKeyGenerator
overload all the methods.