diff --git a/src/FluentNHibernate.Testing/AutoMapping/Apm/AutoPersistenceModelTests.Overrides.cs b/src/FluentNHibernate.Testing/AutoMapping/Apm/AutoPersistenceModelTests.Overrides.cs index a1554a562..b1de37e68 100644 --- a/src/FluentNHibernate.Testing/AutoMapping/Apm/AutoPersistenceModelTests.Overrides.cs +++ b/src/FluentNHibernate.Testing/AutoMapping/Apm/AutoPersistenceModelTests.Overrides.cs @@ -255,11 +255,9 @@ public void JoinedSubclassOverrideShouldOverrideExistingReferencesAny() [Test] public void SubclassOverrideShouldOverrideExistingProperty() { -#pragma warning disable 612,618 var autoMapper = AutoMap.AssemblyOf() .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures") - .Setup(x => x.IsDiscriminated = type => true) -#pragma warning restore 612,618 + .Override(t => t.DiscriminateSubClassesOnColumn("Discriminator")) .Override(c => c.Map(x => x.ExampleProperty).Column("test")); new AutoMappingTester(autoMapper) @@ -290,11 +288,9 @@ public void SubclassOverrideShouldOverrideExistingComponent() [Test] public void SubclassOverrideShouldOverrideExistingHasMany() { -#pragma warning disable 612,618 var autoMapper = AutoMap.AssemblyOf() .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures") - .Setup(x => x.IsDiscriminated = type => true) -#pragma warning restore 612,618 + .Override(t => t.DiscriminateSubClassesOnColumn("Discriminator")) .Override(m => m.HasMany(x => x.Children).Inverse()); new AutoMappingTester(autoMapper) @@ -304,11 +300,9 @@ public void SubclassOverrideShouldOverrideExistingHasMany() [Test] public void SubclassOverrideShouldOverrideExistingHasManyToMany() { -#pragma warning disable 612,618 var autoMapper = AutoMap.AssemblyOf() .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures") - .Setup(x => x.IsDiscriminated = type => true) -#pragma warning restore 612,618 + .Override(t => t.DiscriminateSubClassesOnColumn("Discriminator")) .Override(m => m.HasManyToMany(x => x.Children).Inverse()); new AutoMappingTester(autoMapper) @@ -319,11 +313,9 @@ public void SubclassOverrideShouldOverrideExistingHasManyToMany() [Test] public void SubclassOverrideShouldOverrideExistingHasOne() { -#pragma warning disable 612,618 var autoMapper = AutoMap.AssemblyOf() .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures") - .Setup(x => x.IsDiscriminated = type => true) -#pragma warning restore 612,618 + .Override(t => t.DiscriminateSubClassesOnColumn("Discriminator")) .Override(m => m.HasOne(x => x.Parent)); new AutoMappingTester(autoMapper) @@ -334,11 +326,9 @@ public void SubclassOverrideShouldOverrideExistingHasOne() [Test] public void SubclassOverrideShouldOverrideExistingReferences() { -#pragma warning disable 612, 618 var autoMapper = AutoMap.AssemblyOf() .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures") - .Setup(x => x.IsDiscriminated = type => true) -#pragma warning restore 612,618 + .Override(t => t.DiscriminateSubClassesOnColumn("Discriminator")) .Override(m => m.References(x => x.Parent).Access.Field()); new AutoMappingTester(autoMapper) @@ -348,11 +338,9 @@ public void SubclassOverrideShouldOverrideExistingReferences() [Test] public void SubclassOverrideShouldOverrideExistingReferencesAny() { -#pragma warning disable 612, 618 var autoMapper = AutoMap.AssemblyOf() .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures") - .Setup(x => x.IsDiscriminated = type => true) -#pragma warning restore 612,618 + .Override(t => t.DiscriminateSubClassesOnColumn("Discriminator")) .Override(m => m.ReferencesAny(x => x.DictionaryChild) .EntityIdentifierColumn("one") @@ -363,5 +351,18 @@ public void SubclassOverrideShouldOverrideExistingReferencesAny() .Element("//subclass/any[@name='DictionaryChild']").Exists() .Element("//subclass/map[@name='DictionaryChild']").DoesntExist(); } + + + [Test] + public void SubclassOverrideShouldOverrideDiscriminatorValue() + { + var autoMapper = AutoMap.AssemblyOf() + .Where(t => t.Namespace == "FluentNHibernate.Automapping.TestFixtures") + .Override(t => t.DiscriminateSubClassesOnColumn("Discriminator")) + .Override(m => m.DiscriminatorValue(1)); + + new AutoMappingTester(autoMapper) + .Element("//subclass").HasAttribute("discriminator-value", "1"); + } } } \ No newline at end of file diff --git a/src/FluentNHibernate/Automapping/AutoMapping.cs b/src/FluentNHibernate/Automapping/AutoMapping.cs index 641ebad9c..b7192015b 100644 --- a/src/FluentNHibernate/Automapping/AutoMapping.cs +++ b/src/FluentNHibernate/Automapping/AutoMapping.cs @@ -237,5 +237,15 @@ public void KeyColumn(string column) attributes.Set("Key", Layer.UserSupplied, key); } + + /// + /// Set the discriminator value, if this entity is in a table-per-class-hierarchy + /// mapping strategy. + /// + /// Discriminator value + public void DiscriminatorValue(object discriminatorValue) + { + attributes.Set("DiscriminatorValue", Layer.UserSupplied, discriminatorValue); + } } } \ No newline at end of file