Fluent nHibernate:对不同模式下相同结构的表使用相同的映射文件

Fluent nHibernate: Use the same mapping files for tables with the same structure in different schemas

这是我的映射class:

class MyTableMap : ClassMap<MyTable>
{
    public MyTableMap()
    {
        Schema("mySchema");
        Id(x => x.id);
        Map(x => x.SomeString);
    }
}           

这适用于我的第一个数据库中的 Table ([mySchema].[MyTable])。

但是这个 table ("MyTable") 存在于(实际上很多)不同的数据库中,但是由于任何原因,模式总是被命名为不同的(我无法控制):

所以在数据库 "OtherDB" 中有 Table [SomeOtherSchema].[MyTable] 与 [mySchema].[MyTable 具有相同的结构] 在第一个数据库中。

出于显而易见的原因,我不想为每个数据库创建不同的映射class。

所以:有没有一种方法可以更改映射 class 的模式,这样我只需要创建一个映射 class(不使用单例!)?

看来我得用"DefaultSchema"了。所以我使用了这个映射代码:

class MyTableMap : ClassMap<MyTable>
{
    public MyTableMap()
    {
        Id(x => x.id);
        Map(x => x.SomeString);
    }
}           

当我构建 sessionFactory 时,我必须设置 DefaultSchema:

var configure = Fluently.Configure();
var dbConfig = MsSqlConfiguration.MsSql2012.ConnectionString("Data Source=" + dataSource +
                                                            ";Initial Catalog=" + database +
                                                            ";Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");

//Here I can set the default schema used by my mappings
var dbConfigWithSchema = dbConfig.DefaultSchema(database);  
var fluentDb = configure.Database(dbConfigWithSchema);

var fluentMap = fluentDb.Mappings(mappings);
return fluentMap.BuildSessionFactory();