流畅的nhibernate自动化忽略继承的属性

时间:2011-04-18 18:14:11

标签: c# .net nhibernate fluent-nhibernate automapping

我正在使用流利的nhibernate来映射以下模型:

public abstract class BasePermission : Entity
{
    public abstract string Name { get; }
}
public class ApproveMembershipPermission : BasePermission
{
    public override string Name
    {
        get { return Resources.Permissions.ApproveMembership; }
    }
}

我已经配置为使用每个类层次结构策略的表,除了一件事以外一切正常。我不知道如何告诉FNH igore Name财产。 Currenty我已经生成了这样的映射:

<class name="BasePermission" table="BasePermissions">
    <id name="Id" unsaved-value="0">
      <column name="Id" />
      <generator class="hilo">
        <param name="max_lo">1000</param>
      </generator>
    </id>
    <discriminator type="String">
      <column name="Type" />
    </discriminator>
    <property access="property" name="Name">
      <column name="Name" />
    </property>
    <subclass name="ApproveMembershipPermission" discriminator-value="ApproveMembershipPermission">
      <property access="property" name="Name">
        <column name="Name" />
      </property>
    </subclass>
</class>

我尝试了下一个映射覆盖:

public class BasePermissionMap : IAutoMappingOverride<BasePermission>
{
    public void Override(AutoMapping<BasePermission> mapping)
    {
        mapping.IgnoreProperty(x => x.Name);
    }
}
public class ApproveMembershipPermissionMap : IAutoMappingOverride<ApproveMembershipPermission>
{
    public void Override(AutoMapping<ApproveMembershipPermission> mapping)
    {
        mapping.IgnoreProperty(x => x.Name);
    }
}

它导致以下映射:

<class name="BasePermission" table="BasePermissions">
    <id name="Id" type="System.Int64" unsaved-value="0">
      <column name="Id" />
      <generator class="hilo">
        <param name="max_lo">1000</param>
      </generator>
    </id>
    <discriminator type="String">
      <column name="Type" />
    </discriminator>
    <subclass name="ApproveMembershipPermission" discriminator-value="ApproveMembershipPermission">
      <property access="property" name="Name" />
    </subclass>
</class>

名称仍映射在ApproveMembershipPermission类中。任何人都可以帮助API忽略这个Name属性吗?

1 个答案:

答案 0 :(得分:1)