在父子子类映射中取消映射继承的子属性

时间:2011-04-26 15:55:21

标签: fluent-nhibernate nhibernate-mapping subclass

是否可以取消从Fluent Nhibernate中为父子子类映射继承的属性为单独的表设置?

public class Parent
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int ParentOnlyProperty { get; set; }
}

public class Child : Parent
{
    public string AnotherProperty { get; set; }
}

映射

public class ParentMap : ClassMap<Parent>
{
    public ParentMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.ParentOnlyProperty);
    }
}

public class ChildMap : SubclassMap<Child>
{
    public ChildMap()
    {
        Map(x => x.AnotherProperty);
        Unmap(x => x.ParentOnlyProperty); // is something like this possible?
    }
}

1 个答案:

答案 0 :(得分:0)

我想我真的想在两个实体之间共享一些共同的属性,而不是子类化。以下问题的答案讨论了一个BaseObjectMap:

Fluent Nhibernate How to specify Id() in SubclassMap