3

I'm not too hot on NHibernate / FNH Mapping but I am looking at implementing the state pattern and like the idea of Derick Bailey's article here:

I beleive this was a while ago so the mapping code is out of date, can someone give me a hand to update it for 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);    
   }
}

His article is here for the rest of the code: http://www.lostechies.com/blogs/derickbailey/archive/2008/11/26/mapping-a-state-pattern-with-nhibernate.aspx

Thank you very much!

Paul

jaco0646
  • 15,303
  • 7
  • 59
  • 83
Paul Hinett
  • 1,951
  • 2
  • 26
  • 40
  • Is there anything in particular you're struggling with? Most of the method names had their prefixes dropped (`WithTable` -> `Table`), but that's fairly discoverable with intellisense. – James Gregory Oct 01 '10 at 11:32
  • my intellisense says that DiscriminateSubClassesOnColumn is depreciated and I should use SubclassMap<>...i'm not sure how to use this. – Paul Hinett Oct 01 '10 at 11:52
  • Instead of putting base class and all subclasses in one ClassMap, you have the ClassMap for the base class an separate SubclassMap for each of the subclasses. The discriminator column definition is still in the ClassMap, but the discriminator value is in each SubclassMap. – Rich Oct 01 '10 at 19:40

1 Answers1

1

I am using 1.1 and this is the syntax.

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...
Mark Perry
  • 1,705
  • 10
  • 12