views:

44

answers:

1

I've seen examples of how to do this with the old subclass syntax, but none with the newer : SubclassMap syntax.

Basically, I have multiple discriminators in a table and need to figure out how to do this with FNH.

Thanks, Sam

A: 

We have a base class User and many derived classes from that as Learners, Assessors, Managers, Admins etc.

here is the UserMap

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        this.Id(x => x.Id);

        this.Map(x => x.Active);

        this.Component(
            x => x.Address,
            m =>
            {
                m.Map(x => x.Address1).Length(512);
                m.Map(x => x.Address2);
                m.Map(x => x.Address3);
                m.Map(x => x.Address4);
                m.Map(x => x.City);
                m.Map(x => x.County);
                m.Map(x => x.PostCode);
                m.References(x => x.Country);
            });

        this.References(x => x.CreatedBy);

        this.Map(x => x.CreatedDate).Not.Nullable();

        this.Map(x => x.DeletedDate);

        this.References(x => x.DeletedBy);

        this.Map(x => x.Email);

        this.Map(x => x.Fax);

        this.Map(x => x.FirstName);

        this.References(x => x.Gender);

        this.Map(x => x.LastName);

        this.Map(x => x.LoginName).UniqueKey("ui_loginName").Not.Nullable();

        this.Map(x => x.MiddleName);

        this.Map(x => x.Password);

        this.DiscriminateSubClassesOnColumn("className").Length(64);
    }
}

and an example of Manager

 public class ManagerMap : SubclassMap<Manager>
{
    #region Constructors and Destructors

    /// <summary>
    /// Initializes a new instance of the <see cref="ManagerMap"/> class.
    /// </summary>
    public ManagerMap()
    {
        this.HasManyToMany(x => x.Organisation)
            .ParentKeyColumn("userId")
            .ChildKeyColumn("organisationId")
            .Table("UserOrganisations");

        this.HasMany(x => x.Learners)
            .KeyColumn("managerId")
            .AsBag();
    }

    #endregion
}

Hope that will help you.

isuruceanu

related questions