I'm rephrasing this question: what is the recommended way to join tables across a legacy and a dataobjects database? What we have done is outlined below, but we hope there is a better solution.

Using version 4.6.7, we're trying to join tables across two existing "legacy" databases and a "DataObjects" database. To be able to write such joins, the entities have to all reside in the same domain. However, since we want to be able to create a domain with an upgrademode set to e.g. Recreate or PerformSafely (and those modes are not compatible with accessing legacy data), we found it was necessary to create two separate Domains, 1 with just the entities for the "DataObjects" database and a second Domain with all entities.

Unfortunately it appears that the TypeIds for the same entity type from the DataObjects database are different in the two Domains (it has a higher TypeId in the second domain). I suspect that for the second domain (shown in code below) the legacy assembly entities are assigned TypeIds before the DataObjects entities. Is there any way to guarantee TypeIds remain consistent across the two Domains?

First domain:

DocDbSettings dbSettings = DocDbSettings.Load();
DomainUpgradeMode upMode = (DomainUpgradeMode) DocConvert.ToEnum<DomainUpgradeMode>( dbSettings.UpgradeMode );

string connectionString = dbSettings.ConnectionString;
DomainConfiguration config = DomainConfiguration.Load( dbSettings.ConfigurationName );

DomainConfiguration nu = new DomainConfiguration( dbSettings.Type, connectionString );
config.DefaultDatabase = dbSettings.DbName;
config.DefaultSchema = dbSettings.DefaultSchema;
config.UpgradeMode = upMode;
config.ConnectionInfo = nu.ConnectionInfo;
config.ConnectionInitializationSql = nu.ConnectionInitializationSql;
config.Types.Register(typeof(DataObjectsEntity).Assembly);
var rule = new MappingRule
{
    Assembly = typeof(DataObjectsEntity).Assembly,
    Database = config.DefaultDatabase,
    Schema =  config.DefaultSchema
};
config.MappingRules.Add(rule);
_domain = Xtensive.Orm.Domain.Build( config );

Second Domain:

DocDbSettings dbSettings = DocDbSettings.Load();

DomainUpgradeMode upMode = DomainUpgradeMode.LegacySkip;

string connectionString = dbSettings.ConnectionString;
DomainConfiguration config = DomainConfiguration.Load(dbSettings.ConfigurationName);

DomainConfiguration nu = new DomainConfiguration(dbSettings.Type, connectionString);
config.Name = LegacyDomainName;
config.DefaultDatabase = dbSettings.DbName;
config.DefaultSchema = dbSettings.DefaultSchema;
config.UpgradeMode = upMode;
config.ConnectionInfo = nu.ConnectionInfo;
config.ConnectionInitializationSql = nu.ConnectionInitializationSql;
config.Types.Register(typeof(DataObjectsEntity).Assembly);
config.Types.Register(typeof(LegacyDb1Entity).Assembly, typeof(LegacyDb1Entity).Namespace);
config.Types.Register(typeof(LegacyDb2Entity).Assembly, typeof(LegacyDb2Entity).Namespace);

var rule = new MappingRule
{
    Assembly = typeof(DataObjectsEntity).Assembly,
    Database = config.DefaultDatabase,
    Schema = config.DefaultSchema
};
config.MappingRules.Add(rule);
config.MappingRules.Add(new MappingRule(typeof(LegacyDb1Entity).Assembly, typeof(LegacyDb1Entity).Namespace, dbSettings.LegacyDbName, dbSettings.LegacySchema));
config.MappingRules.Add(new MappingRule(typeof(LegacyDb2Entity).Assembly, typeof(LegacyDb2Entity).Namespace, dbSettings.LibraryDbName, dbSettings.LibrarySchema));
var ret = Xtensive.Orm.Domain.Build(config);

asked Jul 16 '14 at 00:42

DennisDre's gravatar image

DennisDre
7224

edited Jul 16 '14 at 12:33


One Answer:

Hello DennisDre.

Actually no. Let me explain. In UpgradeMode.Perform, UpgradeMode.PerformSafely, UpgradeMode.Skip and UpgradeMode.Validate modes DataObjects extracts schema and metadata(which stored in Metadata.Extension). Metadata describes types, associations and another system info, including TypeIds. And if some type already has TypeId in metadata then TypeId will be the same. When you set DomainConfiguration.UpgradeMode to UpgradeMode.LegacySkip or UpgradeMode.LegacyValidate DataObjects extracts only schema, and doesn't know about TypeIds of types.

answered Jul 16 '14 at 06:26

Alexey%20Kulakov's gravatar image

Alexey Kulakov
66215

Thanks Alexey. I would like to rephrase the question: What is the recommended way to accomplish a join between tables in a legacy database and a dataobjects database?

(Jul 16 '14 at 09:13) DennisDre DennisDre's gravatar image

Hi DennisDre.

In which upgrade mode first domain builds? Is it critical for you to build domains in this sequence?

(Jul 17 '14 at 01:48) Alexey Kulakov Alexey%20Kulakov's gravatar image

First Domain builds in either Recreate, PerformSafely or Validate (we're still in a development phase). Second Domain builds in LegacySkip

(Jul 17 '14 at 08:26) DennisDre DennisDre's gravatar image
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

powered by OSQA