Type Codes

Assume, you have two assemblies containing polymorphic persistent types (AssyA and AssyB) and two applications (AppA and AppB). Let's further assume, that AppA references AssyA and AppB references both AssyA and AssyB. Both applications work against the same database connection. In this case you must make sure, that both applications use the same type codes.

If you only have one application, you don't have to bother about the type codes. NDO generates these codes automatically and stores them in the mapping file. But in the above mentioned case NDO will generate two mapping files, one for each application. The type codes stored in these two files will be used by the two applications in the same database. That means, that the type codes for the polymorphic types defined in AssyA (which is referenced by both applications) have to be the same in both mapping files.

To ensure, that this is the case, NDO uses a hash algorithm to compute the typecode from the FullName of the persistent class. That way, the type code for a given type is always the same. The NDO developers made sure that the algorithm produces well distributed hash codes in a reasonable amount of time to avoid situations, where two types produce the same hash code. Using the hash code algorithm of the .NET Framework seemed not to be a good idea, since this algorithm might change without further notice.

If a hash value collision occurs, NDO starts incrementing the computed hashvalue until an unused typecode is found. This means, that in the above mentioned sample NDO might produce two different typecodes for one and the same type in the two mapping files of the two applications. So you want to make sure, that all applications derive their mapping file from one source (which is the project of the assembly containing the persistent types - in our example AppA and AppB should reference AssyA from the same source).

Keep this in mind, because you know: If the probability, that something evil can occur, is very low, it will happen in your project...

Importing type codes into the database

You can import the typecodes into the database. Check the option Include type codes into the script in the NDO configuration dialog. NDO creates the Sql statements to create an additional table NDOTypes. It contains the type full name, the typecode and the table name, the type is mapped to. NDO doesn't use the imported type codes. NDO always uses the type codes in the mapping file.