流畅的 nhibernate 自动映射忽略继承的属性
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎对您的情况有帮助:
流畅的 Nhibernate 自动映射继承和忽略抽象属性
This seems like it might help in your case:
Fluent Nhibernate AutoMapping Inheritance and Ignoring an Abstract Property