Search code examples
c#nhibernatefluent-nhibernatefluent-nhibernate-mappingautomapping

Having different automapping "configurations"


I want to have two different mapping configurations. I need to somehow pass arguments to conventions so they can behave differently. Beside using lock and static fields how can I do this?


Solution

  • I've found the solution: Conventions.Find allows to find convention instances.

    var map = AutoMap.AssemblyOf<AutomappingConfiguration>(new AutomappingConfiguration())
        .Conventions.AddFromAssemblyOf<AutomappingConfiguration>()
        .UseOverridesFromAssemblyOf<AutomappingConfiguration>();
    
    foreach (var c in map.Conventions.Find<TableConvention>())
    {
        c.AllWritable = allWritable;
    }