Fluent NHibernate
Auto Mapping Overrides (changes)

Showing changes from revision #1 to #2: Added | Removed

When altering entities, you can use the ForMappingsThatDeriveFrom method described in Altering Entities, but that can quickly become cluttered if you're having to alter many entities.

An alternative is to use an IAutoMappingOverride<T>, which is an interface you can implement to override the mappings of a particular auto-mapped class.

public class PersonMappingOverride 
  : IAutoMappingOverride<Person>
{
  public void Override(AutoMap<Person> mapping)
  {
  }
}

This example overrides the auto-mapping of a Person entity. Within the Override method you can perform any actions on the mapping that you can in the Fluent Mappings.

To use overrides, you need to instruct your AutoPersistenceModel instance to use them. Typically this would be done in the context of a Fluent Configuration setup, but I'll just illustrate with the AutoPersistenceModel on it's own.

AutoPersistenceModel.MapEntitiesFromAssemblyOf<Person>()
  .Where(type => type.Namespace == "Entities")
  .UseOverridesFromAssemblyOf<PersonMappingOverride>();

It's the UserOverridesFromAssemblyOf<T> call that instructs the AutoPersistenceModel to read any overrides that reside the assembly that contains T.

For information on how the overrides are implemented, and how you can provide your own customisations to the auto-mapping configuration, have a read of Auto Mapping Configuration Alterations.