gpt4 book ai didi

c# - Fluent nhibernate automappings 忽略继承的属性

转载 作者:行者123 更新时间:2023-11-30 18:05:19 27 4
gpt4 key购买 nike

我正在使用 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 属性吗?

最佳答案

关于c# - Fluent nhibernate automappings 忽略继承的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5707056/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com