diff --git a/src/FluentNHibernate.Testing/Cfg/DuplicateMappingTests.cs b/src/FluentNHibernate.Testing/Cfg/DuplicateMappingTests.cs new file mode 100644 index 000000000..8c36a3477 --- /dev/null +++ b/src/FluentNHibernate.Testing/Cfg/DuplicateMappingTests.cs @@ -0,0 +1,80 @@ +using FluentNHibernate.Automapping; +using FluentNHibernate.Cfg; +using FluentNHibernate.Cfg.Db; +using FluentNHibernate.Mapping; +using NHibernate.Cfg; +using NHibernate.Mapping; +using NUnit.Framework; + +namespace FluentNHibernate.Testing.Cfg +{ + [TestFixture] + public class DuplicateMappingTests + { + private Configuration cfg; + private MappingConfiguration mapping; + + [SetUp] + public void CreateMappingConfiguration() + { + cfg = new Configuration(); + + SQLiteConfiguration.Standard + .InMemory() + .ConfigureProperties(cfg); + + mapping = new MappingConfiguration(); + } + + [Test] + public void FluentMappingOfInheritedAutomappedTypeShouldBeIgnoredForSubclasses() + { + mapping.FluentMappings.Add(typeof(TypeInfoMap)); + mapping.FluentMappings.Add(typeof(MessageTypeMap)); + mapping.AutoMappings.Add(AutoMap.Source(new StubTypeSource(typeof(ActiveRecord)))); + mapping.Apply(cfg); + + var arMapping = cfg.GetClassMapping(typeof(ActiveRecord)); + arMapping.SubclassIterator.GetEnumerator().MoveNext().ShouldBeFalse(); + var messageTypeMapping = cfg.GetClassMapping(typeof(MessageType)) as SingleTableSubclass; + messageTypeMapping.IsJoinedSubclass.ShouldBeFalse(); + } + + #region TestModel + + public class ActiveRecord + { + public virtual int Id { get; set; } + } + + public class TypeInfo : ActiveRecord + { + public virtual int ClassId { get; set; } + } + + public class MessageType : TypeInfo + { + } + + public class TypeInfoMap : ClassMap + { + public TypeInfoMap() + { + Table("TypeInfoNH"); + Id(t => t.Id).GeneratedBy.HiLo("10"); + Map(t => t.ClassId).ReadOnly(); + DiscriminateSubClassesOnColumn("ClassId", 102); + } + } + + public class MessageTypeMap : SubclassMap + { + public MessageTypeMap() + { + DiscriminatorValue(305); + } + } + + #endregion + } +} diff --git a/src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj b/src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj index 501dc5a9e..3a9970da6 100644 --- a/src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj +++ b/src/FluentNHibernate.Testing/FluentNHibernate.Testing.csproj @@ -126,6 +126,7 @@ + @@ -416,10 +417,8 @@ - - diff --git a/src/FluentNHibernate/PersistenceModel.cs b/src/FluentNHibernate/PersistenceModel.cs index 675256432..f81be8393 100644 --- a/src/FluentNHibernate/PersistenceModel.cs +++ b/src/FluentNHibernate/PersistenceModel.cs @@ -312,6 +312,8 @@ public bool ValidationEnabled internal void ImportProviders(PersistenceModel model) { + EnsureMappingsBuilt(); + model.classProviders.Each(x => { if (!classProviders.Contains(x))