Map a dictionary with a custom key type using FluentNHibernate

81 Views Asked by At

I need to map a Dictionary<TenthNm,double> in one of my ClassMaps, but the key is custom type (essentially, TenthNm is an object that has only an int property). There is a similar question, which lead me to this:

      HasMany(x => x.ExcitationCurve)
        .Table("PresetCurveExcitation")
        .KeyColumn("PresetCurveId")
        .AsMap<TenthNm>("Wavelength")
        .Element("Value");

This works, but the TenthNm object is stored as a BLOB, where it simply could be an int.

In other ClassMaps, with only a single TenthNm property, I use

      Map(x => x.Wavelength).CustomType<TenthNmUserType>();

with TenthNmUserType being a class implementing IUserType, so it is stored as an int there.

But how can I tell NHibernate to use TenthNmUserType (or a custom int mapping)?

1

There are 1 best solutions below

0
Jakob On

A colleague found the answer: Just use the AsMap<TenthNmUserType> instead of AsMap<TenthNm>, so it now looks like this:

HasMany(x => x.ExcitationCurve)
        .Table("PresetCurveExcitation")
        .KeyColumn("PresetCurveId")
        .AsMap<TenthNmUserType>("Wavelength")
        .Element("Value");