Since it is boring having to specify every time the Schema a table belongs to, it would be nice having a conventional strategy to automatically wire up this information. With NHibernate mapping by code functionality this is simple. The strategy I propose is having the last part of the entity namespace being equal with the schema. So for example we have an entity Product in the schema named Production we define the entity as:
MyEntities.Production.Product
Then by using a ConventionModelMapper we can write:
public class MyModelMapper:ConventionModelMapper
{
public MyModelMapper()
{
this.BeforeMapClass += (modelInspector, type, customizer) =>
{
customizer.Schema(type.Namespace.Split('.').Last());
};
}
}
And we achieve to write less line again :)