Reputation: 1567
For a project I'm working on I'm using a custom type to deal with IP Addresses in the database as a binary and address family pair.
If I attempt to map to my custom type in a SubclassMap it fails with a Mapping exception during startup
NHibernate.MappingException: property mapping has wrong number of columns: AddressAsset.Address type: IPAddressBinaryUserType
The failed mapping code is as follows:
public class AbstractAssetMap : ClassMap<AbstractAsset>
{
public AbstractFirewallAssetMap()
{
Table("asset");
Id(x => x.FirewallAssetSk).Column("asset_sk").GeneratedBy.Native();
DiscriminateSubClassesOnColumn<string>("type");
// ... other property mappings
}
}
public class AddressAssetMap : SubclassMap<AddressAsset>
{
public AddressAssetMap()
{
DiscriminatorValue(AbstractFirewallAsset.FirewallAssetType.Address);
Map(x => x.Address)
.CustomType<IPAddressBinaryUserType>()
.Columns.Add("address_family", "address");
}
}
// ... other SubclassMaps of AbstractAsset subclasses
If I remove one of the columns a MappingException is no longer thrown. This however is not a solution as I need the data from both columns.
Likewise, if I remove the subclassing and explicitly map the sub class using the same custom type it appears to work, and does not fail during mapping. eg:
public class AddressAssetMap : ClassMap<AddressAsset>
{
public AddressAssetMap()
{
Table("asset");
Id(x => x.FirewallAssetSk).Column("asset_sk").GeneratedBy.Native();
Map(x => x.Address)
.CustomType<IPAddressBinaryUserType>()
.Columns.Add("address_family", "address");
// ... other property mappings
}
}
What is the proper way to map a Multi-column usertype inside a fluent NHibernate SubclassMap?
Upvotes: 2
Views: 669
Reputation: 206
You should try upgrading fluent nhibernate. Please take a look at known issue https://github.com/jagregory/fluent-nhibernate/issues/210
Upvotes: 3