On Apr 4, 2:47 pm, Lorenzo Dieryckx <
lorenzo.diery...@gmail.com>
wrote:
I solved this myself.
Since it seems impossible to access any configuration in the ClassMap
(and I didn't want to start reading config files manually there) and
since you can't have dependencies injected in the ClassMap via some
IoC framework (Classmaps need a parameterless constructor),
I had to do it the "old fashioned way" with a singleton class:
The singleton:
public class DefaultSchemaProvider
{
private static DefaultSchemaProvider _instance = null;
private string _defaultSchema = null;
public static DefaultSchemaProvider Instance
{
get
{
if (_instance == null)
_instance = new DefaultSchemaProvider();
return _instance;
}
}
public void SetDefaultSchema(string defaultSchema)
{
_defaultSchema = defaultSchema;
}
public string GetDefaultSchema()
{
return _defaultSchema;
}
}
During configuration:
var nhibernateCfg = new NHibernate.Cfg.Configuration();
nhibernateCfg.Configure(ConfigurationFile);
DefaultSchemaProvider.Instance.SetDefaultSchema(nhibernateCfg.GetProperty("default_schema"));
in the classmap:
public class CustomerMap : ClassMap<Customer>
{
public CustomerMap()
{
var defaultSchema =
DefaultSchemaProvider.Instance.GetDefaultSchema() + ".";
Table("Customers");
Id(x => x.Id).Column("Customer_id");
Map(x => x.Description).Column("Name");
Component(c => c.CustomerType, c =>
{
c.Map(x => x.Id).Column("Customer_type");
c.Map(x => x.Description).Formula(
"(SELECT ct.value FROM " + defaultSchema +
"customer_types ct WHERE ct.field='description' AND ct.typeid =
Customer_type)");
});
HasMany(x =>
x.ArticleLinks).KeyColumn("VENR").Access.CamelCaseField(Prefix.Underscore);
}
}