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
7●2●2●4