How to map a list of an interface to a concrete class
I'd like to map a list of an interface This is my object:
public class Foo
{
public virtual IList<IBar> Bars { get; protected set; }
}
I have several implementations of IBar
in my domain model. How do I specify which IBar
implementation Foo
is using with Fluent NHibernate? I'm using auto mapping and would love if there was a solution with overrides.
I feel like there's a missing Class()
method somewhere, but I don't know how to map this with NHibernate, so I'm not sure what I want to do is even possible.
2 Posted by Asbjørn Ulsberg on 25 Oct, 2010 12:22 PM
I can add that in the opposite direction of the many-to-one relationship, I have the following:
And I map this with the following override:
3 Posted by Asbjørn Ulsberg on 25 Oct, 2010 04:21 PM
In NHibernate, this seems to be the way to solve it:
However, I find no way to modify
<one-to-many class="" />
with FNH, at least not withIAutoMappingOverride
. Is there another way to access the@class
attribute so I can set it toBar
instad ofIBar
?Support Staff 4 Posted by James Gregory on 26 Oct, 2010 12:20 PM
Looks like that's not exposed through either the
ClassMap
API, or theIAutoMappingOverride
s. That's a bummer.I think the only option you have (apart from using HBMs) is to create an
IHasManyConvention
and modify theRelationship
property.That might not be perfect, as I don't have a compiler to hand, but it should be close enough.