简体   繁体   中英

Fluent NHibernate Mapping Left Join

I know that this code has a bit of smell but it suits this project in this specific implementation.

public class InvestmentAdvisorMap: ClassMap<InvestmentAdvisor>
{
    public InvestmentAdvisorMap()
    {
        Id(x => x.EmployeeID).GeneratedBy.Assigned()
            .Access.CamelCaseField(Prefix.Underscore);

        Not.LazyLoad();
        Table("Employee");
        //need mapping to tierName here???? that links to join table
    }
}

public class InvestmentAdvisor
{
    private readonly Guid _employeeID;
    private string _tierName;

    public Tier Tier
    {
        get
        {
            switch (_tierName)
            {
                case "<$100K":
                    return Tier.LessThan100K;
                case "$100K+":
                    return Tier.MoreThan100K;
                case "$240K+":
                    return Tier.MoreThan240K;
                case "$400K+":
                    return Tier.MoreThan400K;
                case "$600K+":
                    return Tier.MoreThan600K;
                case "$1M+":
                    return Tier.MoreThan1M;
                default:
                    return Tier.LessThan100K;
            }
        }
    }

    public string TierName
    {
        get {
            return _tierName;
        }
    }

    public Guid EmployeeID
    {
        get { return _employeeID; }
    }
}

}

I have a join table where there is a one to one relationship on tier where which has employeeID and TierName, I cant for the life of me figuire out how to do the Mapping class, basically a composite entity but not finding great examples

How about inheritancehirarchy?

public abstract class Tier
{
    public abstract void DoSomething();
}

class TierMap : ClassMap<Tier>
{
    public TierMap()
    {
        DiscriminateSubClassesOnColumn("TierName");
    }
}

public class LessThan100K : Tier
{
    public override void DoSomething()
    {
        // Do something useful
    }
}

class LessThan100KMap : SubclassMap<LessThan100K>
{
    public LessThan100KMap()
    {
        DiscriminatorValue("<$100K");
    }
}

and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM