我对NHibernate / FNH Mapping并不热,但我正在考虑实现状态模式,并且像Derick Bailey的文章一样:
我相信这是不久之前所以映射代码已过时,有人可以帮我更新FNH 1.1吗?
public class OrderStatusMap: ClassMap<OrderStatus>
{
public OrderStatusMap()
{
CreateMap();
}
public void CreateMap()
{
DefaultAccess.AsProperty();
WithTable("OrderStates");
Id(s => s.Id).GeneratedBy.Assigned();
DiscriminateSubClassesOnColumn<string>("Name")
.SubClass<InProcessStatus>()
.IsIdentifiedBy(OrderStatus.InProcess.Name)
.MapSubClassColumns(x => { })
.SubClass<TotaledStatus>()
.IsIdentifiedBy(OrderStatus.Totaled.Name)
.MapSubClassColumns(x => { })
.SubClass<TenderedStatus>()
.IsIdentifiedBy(OrderStatus.Tendered.Name)
.MapSubClassColumns(x => { })
.SubClass<DeliveredStatus>()
.IsIdentifiedBy(OrderStatus.Delivered.Name)
.MapSubClassColumns(x => { })
Map(s => s.Name);
}
}
他的文章是针对其余代码的: http://www.lostechies.com/blogs/derickbailey/archive/2008/11/26/mapping-a-state-pattern-with-nhibernate.aspx
非常感谢!
保
答案 0 :(得分:1)
我使用1.1,这是语法。
public class OrderStatusMap: ClassMap<OrderStatus>
{
public OrderStatusMap()
{
DefaultAccess.AsProperty();
WithTable("OrderStates");
Id(s => s.Id).GeneratedBy.Assigned();
Map(s => s.Name);
DiscriminateSubClassesOnColumn<string>("Name");
}
}
public class InProcessStatusMap : SubclassMap<InProcessStatus>
{
public InProcessStatusMap()
{
DiscriminatorValue(OrderStatus.InProcess.Name);
}
}
public class TotaledStatusMap : SubclassMap<TotaledStatus>
{
public TotaledStatusMap()
{
DiscriminatorValue(OrderStatus.TotaledStatus.Name);
}
}
etc...