Mapping a complex component as a dictionary key
Is there a way to map this IDictionary<RangeOf<Tons>, double>
?
Giving...
public class Tons
{
public int Amount{get; private set;}
}
And...
public class RangeOf<T>
{
public T Start { get; private set; }
public T End { get; private set; }
}
RangeOf<Tons>
should be mapped as a component that is at the same time the key of the dictionary.
Thank you
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Hudson Akridge on 02 Mar, 2010 05:26 PM
I don't believe we support entity-key or composite-map-key in a dictionary. At least I tried this a month or so ago and couldn't get it working.
To be honest, in NHibernate in general, this is going to cause you headaches. It's best to map the "RangeOf" class including the double field as a class and map that.
Also, when using generics, unless something has changed, you have to explicitly map the type so you'd have to create a mapping for every implementation of the generic type.
3 Posted by diver on 02 Mar, 2010 06:17 PM
I might have misunderstood you, but the following is working like a charm:
Voyage is an entity. Here is the mapping:
As you can see, an Entity as a key and RangeOf<> as the value.
Here is the hbm file I'm using to map a IDictionary<RangeOf, double>:
This "composite-index / element" is what I'm looking for. After a quick review of the source codes, I realized that it is not (yet) supported. I'll take a closer look as soon as I can.
Thank you very much for your respond. FNH is awesome!
Support Staff 4 Posted by Hudson Akridge on 02 Mar, 2010 06:24 PM
Yup, that's basically what I mean. The entity being mapped as an index/key is not supported in FNH afaik.
Hudson Akridge resolved this discussion on 02 Mar, 2010 06:24 PM.