开发者

NHibernate Component inheritance

Is it possible to do inheritance with NHib开发者_如何学运维ernates component? A quick google returned only a hand full of appropriate results (all blogs) and all were written some time ago so was wondering if it is available yet?

if not how do you handle it instead?


It's not currently possible. If you need inheritance, you have to map an entity.


In addition to what Diego had said, there is also an option to implement custom hydration/dehydration for hierarchy using IUserType. See this article for details (its Java but the same mechanism can be used in C#).

And Hibernate feature request is here. NHibernate version is here, please vote.


Yes.

public class A { }

public class B : A { }

public sealed class C : B { }

public abstract class BaseAMap<T> : ComponentMap<T> where T : A {
    public BaseAMap() {
        // Map A here
    }
}

public class AMap : BaseAMap<A>  {
}

public class BaseBMap<T> : BaseAMap<T> where T : B  {
    public BaseBMap () {
        // Map B (excluding A)
    }
}

public class BMap : BaseBMap<B>  {
}

public sealed class CMap : BaseBMap<B>  {
    public CMap () {
        // Map C (excluding B)
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜