This is already supported and you don't have to do anything.
Given this class:
public class Foo : IBar, IBaz {...}
Mapped with just a single <class> that doesn't mention the interfaces, the
following test passes:
var foo = session.CreateCriteria<IBar>().Add(/*filter on IBar or common
properties*/).UniqueResult();
var sameFoo = session.CreateCriteria<IBaz>().Add(/*filter on IBaz or
common properties*/).UniqueResult();
Assert.AreSame(foo, sameFoo);
For HQL you need to import the interface (
http://nhforge.org/doc/nh/en/index.html#mapping-declaration-import), but
that's it.
Diego
On Fri, Sep 24, 2010 at 12:11, Patrick Earl <[email protected]> wrote:
> Since I like talking to myself so much, I thought I'd reply with some
> other backing thoughts.
>
> We currently implement this within our own repository class. When it
> sees a request for ISomething, it consults a map and converts that to
> a request for Something. I've been looking at using ActiveRecord
> again (we moved away from it due to this interface mapping issue) and
> I've considered implementing the interface mapping in ActiveRecord.
> When I thought about it further though, it seemed more like something
> that ActiveRecord shouldn't need to worry about (aside from the
> mapping perspective) and something that should be implemented in
> NHibernate itself. Obviously it would be nice if things like Linq and
> QueryOver worked against the interfaces as well.
>
> So, to summarize, I'm pretty sure that the ORM is the one that should
> take responsibility, and that's why I'm interested in implementing
> support for this in NHibernate.
>
> Patrick Earl
>