我知道这段代码有点嗅觉,但在这个特定的实现中它适合这个项目。
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; }
}
}
}
我有一个连接表,其中层上有一对一的关系,其中有employeeID和TierName,我不能告诉我如何做Mapping类,基本上是一个复合实体,但没有找到很好的例子
答案 0 :(得分:0)
继承层次结构怎么样?
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");
}
}
等等。