converting table-per-subclass to table-per-class-heirachy

Original Post Berryl Hesh's Avatar

Berryl Hesh

26 Mar, 2010 06:07 PM via web

Hello

The code for both is below, with commented lines being the attempt to
change the per-subclass into a class-
hierarchy strategy. The subclass mapping works in the sense that I do not get errors.

The error I get with my per-class-hierachy attempt is that the discriminator column cannot be null, which
is reasonable but I thought that NHib would populate the values in the
mapping (ie, "ACCOUNT" and "PROJECT").

Can someone please help do this?

Cheers,
Berryl

public class ActivityBaseMap : IAutoMappingOverride<ActivityBase>
{
    public void Override(AutoMapping<ActivityBase> mapping)
    {
        mapping.IgnoreProperty(x => x.BusinessId);
        mapping.IgnoreProperty(x => x.Description);
        mapping.IgnoreProperty(x => x.TotalTime);
        mapping.IgnoreProperty(x => x.UniqueId);

        //mapping.DiscriminateSubClassesOnColumn("SubClassType");
    }
}

public class AccountingActivityMap :

SubclassMap

{
    public void Override(AutoMapping<AccountingActivity> mapping)
    {
        mapping.References(x => x.Account);
        //DiscriminatorValue("ACCOUNT");
    }
}

public class ProjectActivityMap : SubclassMap<ProjectActivity>
{
    public void Override(AutoMapping<ProjectActivity> mapping)
    {
        mapping.References(x => x.Project);
        //DiscriminatorValue("PROJECT");
    }
}

I posted this at the google forum before I realized this forum was available and preferred, so please forgive the double posting.

Cheers,
Berryl

  1. 2 Posted by Berryl Hesh on 28 Mar, 2010 03:39 AM

    Berryl Hesh's Avatar

    I was missing the connection between telling FNH Automapping that I wanted to use Subclass strategy, as the big problem. The only thing that still looks off is the discriminator value, which is still the subclass Type and not the string value I set in the mapping.

    Appreciate any feedback.

    Cheers,
    Berryl

    AUTOMAP SETUP:
    // shotgun approach for now m.Setup(s =>

            {
                s.SubclassStrategy = t => SubclassStrategy.Subclass;
            });
    

    MAPPING OVERRIDES:

    public class ActivityBaseMap : IAutoMappingOverride<ActivityBase>
    {
        public void Override(AutoMapping<ActivityBase> mapping)
        {
            ....
            mapping.DiscriminateSubClassesOnColumn("SubClassType");
        }
    }
    
    public class AccountingActivityMap : SubclassMap<AccountingActivity>
    {
        public AccountingActivityMap() {
            References(x => x.Account);
            DiscriminatorValue("ACCOUNT");
        }
    }
    
    public class ProjectActivityMap : SubclassMap<ProjectActivity>
    {
        public ProjectActivityMap() {
            References(x => x.Project);
            DiscriminatorValue("PROJECT");
        }
    }
    

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is the last month of the year?

    Recent Discussions

    05 Jul, 2010 10:29 PM
    05 Jul, 2010 12:45 PM
    05 Jul, 2010 12:42 PM
    05 Jul, 2010 12:17 PM
    05 Jul, 2010 12:12 PM

     

    03 Jul, 2010 12:26 AM
    02 Jul, 2010 02:17 PM
    02 Jul, 2010 08:18 AM
    02 Jul, 2010 12:20 AM
    01 Jul, 2010 10:14 PM