Skip to content

Commit 885e2af

Browse files
committed
Fixed bug with explicit MetaType on ReferencesAny mapping clearing out meta values.
Conflicts: src/FluentNHibernate/Mapping/AnyPart.cs
1 parent 24d7207 commit 885e2af

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/FluentNHibernate.Testing/DomainModel/Mapping/AnyPartTester.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,27 @@ public void AnyIsAfterIdElement()
173173

174174
mapTest.Element("class/id").ShouldBeInParentAtPosition(0);
175175
}
176+
177+
178+
[Test]
179+
public void SpecificMetaTypeShouldNotClearMetaValues()
180+
{
181+
var mapTest = new MappingTester<MappedObject>()
182+
.ForMapping(map =>
183+
{
184+
map.Id(x => x.Id);
185+
map.ReferencesAny(x => x.Parent)
186+
.EntityIdentifierColumn("AnyId")
187+
.EntityTypeColumn("AnyType")
188+
.IdentityType(x => x.Id)
189+
.MetaType<int>()
190+
.AddMetaValue<SecondMappedObject>("1");
191+
});
192+
193+
mapTest
194+
.Element("class/any/meta-value")
195+
.HasAttribute("value", "1")
196+
.HasAttribute("class", typeof(SecondMappedObject).AssemblyQualifiedName);
197+
}
176198
}
177199
}

src/FluentNHibernate/Mapping/AnyPart.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,10 @@ AnyMapping IAnyMappingProvider.GetAnyMapping()
168168
if (!mapping.IsSpecified("Name"))
169169
mapping.Name = member.Name;
170170

171+
metaValues.Each(mapping.AddMetaValue);
171172
if (!mapping.IsSpecified("MetaType"))
172173
{
173-
if (metaValues.Count() > 0)
174-
{
175-
metaValues.Each(mapping.AddMetaValue);
176-
mapping.MetaType = new TypeReference(typeof(string));
177-
}
178-
else
179-
mapping.MetaType = new TypeReference(member.PropertyType);
174+
mapping.MetaType = metaValues.Count() > 0 ? new TypeReference(typeof(string)) : new TypeReference(member.PropertyType);
180175
}
181176

182177
foreach (var column in typeColumns)

0 commit comments

Comments
 (0)