jagregory/fluent-nhibernate — Issue #104: mapping.Component throws exception in IAutoMappingOverride`1
Author: hazzik
Created: 2011-10-18 05:29:34+00:00
State: open

I've following configuration:

```csharp
public class AutomappingConfiguration : DefaultAutomappingConfiguration
{
private readonly HashSet components = new HashSet
{
typeof (DocumentNumber)
};

public override bool IsComponent(Type type)
{
return components.Contains(type);
}

public override string GetComponentColumnPrefix(FluentNHibernate.Member member)
{
//replaces camel case with underscores "IncomingDocument" => "INCOMING_DOCUMENT"
//and adds undersocre at end
return string.Format("{0}_", Regex.Replace(member.Name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1_").ToUpper());
}

//rest of configuration
}
```
And alteration for my entity.

```csharp
public class IncomingDocumentMap : IAutoMappingOverride
{
public void Override(AutoMapping mapping)
{
mapping.Component(x => x.IncomingNumber) //incoming number is type of DocumentNumber
.ColumnPrefix("INCOMING_"); // I need to override default column prefix for component.
}
}
```

When I try to build sesion factory I've got following exeption:

```
System.InvalidOperationException: Tried to add component 'IncomingNumber' when already added.
at FluentNHibernate.MappingModel.MappedMembers.AddComponent(IComponentMapping componentMapping) in d:\Builds\FluentNH\src\FluentNHibernate\MappingModel\MappedMembers.cs: line 133
at FluentNHibernate.Automapping.Steps.ComponentStep.Map(ClassMappingBase classMap, Member member) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\Steps\ComponentStep.cs: line 26
at FluentNHibernate.Automapping.AutoMapper.TryMapProperty(ClassMappingBase mapping, Member member, IList`1 mappedMembers) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 170
at FluentNHibernate.Automapping.AutoMapper.<>c__DisplayClasse.b__d(Member x) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 158
at FluentNHibernate.Utils.CollectionExtensions.Each(IEnumerable`1 enumerable, Action`1 each) in d:\Builds\FluentNH\src\FluentNHibernate\Utils\CollectionExtensions.cs: line 15
at FluentNHibernate.Automapping.AutoMapper.ProcessClass(ClassMappingBase mapping, Type entityType, IList`1 mappedMembers) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 156
at FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList`1 mappedMembers) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 43
at FluentNHibernate.Automapping.AutoMapper.Map(Type classType, List`1 types) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 186
at FluentNHibernate.Automapping.AutoPersistenceModel.AddMapping(Type type) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 209
at FluentNHibernate.Automapping.AutoPersistenceModel.CompileMappings() in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 173
at FluentNHibernate.Automapping.AutoPersistenceModel.Configure(Configuration configuration) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 199
at FluentNHibernate.Cfg.AutoMappingsContainer.Apply(Configuration cfg, PersistenceModel model) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\AutoMappingsContainer.cs: line 86
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\MappingConfiguration.cs: line 80
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 249

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 264
```

If I remove `typeof(DocumentNumber)` from component types I've got exception which says that property is references unmapped class

```
NHibernate.MappingException: An association from the table INCOMING_DOCUMENT refers to an unmapped class: DocumentNumber
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at NHibernate.Cfg.Configuration.BuildSessionFactory()

```