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

发布于 2024-11-01 19:24:29 字数 2403 浏览 0 评论 0原文

我正在使用 Fluent 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 忽略 Name 属性。目前我已经生成了这样的映射:

<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 属性吗?

I'm using fluent nhibernate to map following model:

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

I have configured to use table per class hierarchy strategy and everything works fine except one thing. I don't know how to tell FNH to igore Name property. Currenty I have such mapping generated:

<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>

I have tried next mapping overrides:

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);
    }
}

And it leads to following mapping:

<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>

Name is still mapped in ApproveMembershipPermission class. Can anybody help with API to ignore this Name property?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文