-
Notifications
You must be signed in to change notification settings - Fork 936
Description
I am using a custom type in my code to store small base 10 decimal values without the memory overhead of System.Decimal (4 bytes vs 16 bytes).
public struct SmallDecimal : IEquatable<SmallDecimal>, IEquatable<decimal>, IComparable, IComparable<SmallDecimal>
{...}
I also have a custom IUserType that maps this type.
I am using ConventionModelMapper to set up a number of conventions including one that inspects the property type and sets the appropriate IUserType
mapper.BeforeMapProperty += (mi, propertyPath, map) =>
{
var propertyType = propertyPath.LocalMember.GetPropertyOrFieldType();
if (propertyType.Equals(typeof(SmallDecimal)) || propertyType.Equals(typeof(SmallDecimal?)))
{
map.Type(typeof(SmallDecimalUserType), null);
}
};
This works correctly as long as I explicitly map every property that is SmallDecimal, but what I want is to be able to set up some kind of convention such that any property of type SmallDecimal is automatically mapped as a property with a type SmallDecimalUserType without the explicit mapping. (I have a lot of properties across a lot of classes that are currently automatically mapped as decimal here that I want to change to SmallDecimal)
At the moment, any property I do not explicitly map that has a type of SmallDecimal ends up mapped as a component.
I've never used fluent NHibernate but it appears that I could achieve the above with their UserTypeConvention.
I'd rather stick with the native mapping-by-code Is there a parallel in mapping by code?