Skip to content

Commit f30837b

Browse files
author
visubesy
authored
Use Type as PropertyPart CustomType instead of only name (#347)
* Don't use only name for PropertyPart.CustomType - Use the constructor of TypeReference with Type argument instead of the constructor with string argument in the overloads of CustomType in PropertyPart where an explicit Type is passed. - This fixes the problem that Fluent NHibernate may map a wrong type for a property although an explicit type was passed to CustomType. This problem can happen if there are two types with names which only differ in upper / lower case. Such similar type names can e.g. be caused by obfuscation tools. * Adapt tests to new behaviour of PropertyPart - The production code of the CustomType overloads of PropertyPart was changed to use a different constructor of TypeReference when an explicit Type was given. This caused two tests to fail although the code still should work correctly. - Change failing tests to expect the new behaviour. +semver:fix
1 parent bf7ead4 commit f30837b

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/FluentNHibernate.Testing/ConventionsTests/OverridingFluentInterface/PropertyConventionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void TypeShouldntBeOverwritten()
6565

6666
Convention(x => x.CustomType<int>());
6767

68-
VerifyModel(x => x.Type.Name.ShouldEqual(typeof(CustomUserType).AssemblyQualifiedName));
68+
VerifyModel(x => x.Type.GetUnderlyingSystemType().ShouldEqual(typeof(CustomUserType)));
6969
}
7070

7171
[Test]
@@ -285,4 +285,4 @@ void VerifyModel(Action<PropertyMapping> modelVerification)
285285
}
286286

287287
#endregion
288-
}
288+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ public void EnumsDontGetTypeOverriddenByConventionsIfExplicitlySet()
108108
{
109109
new MappingTester<MappedObject>()
110110
.ForMapping(m => m.Map(x => x.Color).CustomType(typeof(int)))
111-
.Element("class/property[@name='Color']").HasAttribute("type", typeof(int).Name);
111+
.Element("class/property[@name='Color']").HasAttribute("type", typeof(int).AssemblyQualifiedName);
112112
}
113-
}
113+
}

src/FluentNHibernate/Mapping/PropertyPart.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class PropertyPart : IPropertyMappingProvider
1212
{
1313
readonly Member member;
1414
readonly Type parentType;
15-
readonly AttributeStore attributes = new AttributeStore();
16-
readonly AttributeStore columnAttributes = new AttributeStore();
15+
readonly AttributeStore attributes = new();
16+
readonly AttributeStore columnAttributes = new();
1717

1818
bool nextBool = true;
1919

@@ -171,7 +171,8 @@ public PropertyPart CustomType(Type type)
171171
if (typeof(ICompositeUserType).IsAssignableFrom(type))
172172
AddColumnsFromCompositeUserType(type);
173173

174-
return CustomType(TypeMapping.GetTypeString(type));
174+
attributes.Set("Type", Layer.UserSupplied, new TypeReference(type));
175+
return this;
175176
}
176177

177178
/// <summary>
@@ -194,11 +195,7 @@ public PropertyPart CustomType(string type)
194195
public PropertyPart CustomType(Func<Type, Type> typeFunc)
195196
{
196197
var type = typeFunc.Invoke(member.PropertyType);
197-
198-
if (typeof(ICompositeUserType).IsAssignableFrom(type))
199-
AddColumnsFromCompositeUserType(type);
200-
201-
return CustomType(TypeMapping.GetTypeString(type));
198+
return CustomType(type);
202199
}
203200

204201
void AddColumnsFromCompositeUserType(Type compositeUserType)

0 commit comments

Comments
 (0)