4

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?

Sly
  • 15,046
  • 12
  • 60
  • 89
  • these are pure shots in the dark; I think you should just play around with all possible options and permutations till something sticks- try having the IgnoreProperty part only in the base class, or only in the subclass; maybe try having the property in the sub class as virtual and not override... – J. Ed Apr 19 '11 at 20:32
  • what version of fluent nh are you using? – Cole W Apr 20 '11 at 03:07

1 Answers1

1

This seems like it might help in your case:
Fluent Nhibernate AutoMapping Inheritance and Ignoring an Abstract Property

Community
  • 1
  • 1
Cole W
  • 15,123
  • 6
  • 51
  • 85
  • Thanks, will I will try try it a bit later. If it works, I'll accept the answer. – Sly Apr 20 '11 at 06:34