fluent nHibernate mapping of subclassed structure

Posted by Codezy on Stack Overflow See other posts from Stack Overflow or by Codezy
Published on 2010-04-13T17:59:37Z Indexed on 2010/04/13 18:03 UTC
Read the original article Hit count: 395

I have a workflow class that has a collection of phases, each phase has a collection of tasks. You can design a workflow that will be used by many engagements. When used in engagement I want to be able to add properties to each class (workflow, phase, and task). For example a task in the designer does not have people assigned, but a task in an engagement would need extra properties like who is assigned to it. I have tried many different approaches using subclasses or interfaces but I just can't get it to map the way I want. Currently I have the engagement level versions as subclasses, but I can't get Engagement phases to map to engagement workflows.

Public Class WorkflowMapping
  Inherits ClassMap(Of Workflow)

  Sub New()

     Id(Function(x As Workflow) x.Id).Column("Workflow_Id").GeneratedBy.Identity()
     Map(Function(x As Workflow) x.Description)
     Map(Function(x As Workflow) x.Generation)
     Map(Function(x As Workflow) x.IsActive)
     HasMany(Function(x As Workflow) x.Phases).Cascade.All()

  End Sub

End Class

Public Class EngagementWorkflowMapping Inherits SubclassMap(Of EngagementWorkflow)

  Sub New()
     Map(Function(x As EngagementWorkflow) x.ClientNo)
     Map(Function(x As EngagementWorkflow) x.EngagementNo)
  End Sub

End Class

How would you approach mapping this in fluent (or hbm) so that you could load just the workflow base class when designing the flow, or the engagement subclass versions of each when being used by an engagement?

© Stack Overflow or respective owner

Related posts about fluent

Related posts about nhibernate