This is another issue I was having that I couldn't find a way around,
at least not and still maintain the DB / Entity model I wanted.

I was told that NHibernate does support this sort of inheritance
though... but he may have been mistaken. Fluent NHibernate certainly
didn't. My model was for workflows, where by there was a root level
WorkflowStep, and then each step could be one of Reviewer or Workflow
(Which could be a ParallelWorkflow or SerialWorkflow). I accomplished
this by having everything inherit from WorkflowStep (instead of having
WorkflowStep > Workflow > Parallel or SerialWorkflow).

The downside to that was that I needed an extra database table, which
I'm betting is what you're trying to avoid (Unless your inheritance
structure is deeper in depth than mine...). My solution required that
there be a table-per-entity (Reviewers, ParallelWorkflows,
SerialWorkflows) as well as a top end WorkflowStep table. What I
WANTED was three tables (Reviewers, Workflows, and WorkflowSteps)
instead of four. This would require a discriminator on the Subclass
Workflow for determining whether to make it a Serial or
ParallelWorkflow entity though, which Fluent NHibernate just doesn't
do unfortunately.

If there IS a way to map this in NHibernate, and we can get it into a
future version of Fluent NHibernate, that would be great! I'd put my
vote in for it!

On Aug 19, 4:09 am, Mikael Henriksson <[email protected]> wrote:
> Thanks David I'll try that after work would have yesterday but I was too
> tired to try crazy ideas. ;)
>
> On Wed, Aug 19, 2009 at 9:39 AM, David Perfors <[email protected]> wrote:
>
> > What I did in some cases whas to make a Base class map like:
> > class Person<T> : ClassMap<T>
> > {
> > }
>
> > and the subclasses inherit from Person<T> instead of ClassMap<T> That
> > whay you still have the power of OO subclasses,
> > but the database see it as two different tables...
>
> > (not sure if this is what you want though...)
>
> > David Perfors.
>
> > On Aug 19, 9:00 am, Mikael Henriksson <[email protected]> wrote:
> > > Gaaah all these limitations everywhere :)
> > > Not that I care about the database it's just frustrating that I can't
> > make
> > > it perfect!! Not saying it's your fault James, just saying that's all.
> > I'll
> > > try to make it work in a different manner. What I was actually trying to
> > > accomplish was to not have to repeat myself too much. So this would be my
> > > next step. Can't I just use the same ClassMap for these guys?.
> > > On Tue, Aug 18, 2009 at 9:56 PM, James Gregory <[email protected]
> > >wrote:
>
> > > > I assume what you're trying to do is have a Person table, and a
> > > > BoardMembers table, with BoardMember being a joined-subclass, and then
> > any
> > > > derived BoardMember's being discriminated...?
>
> > > > If that is the case, then I'm afraid you're out of
> > > > luck. Unless somebody knows otherwise, I'm pretty sure you can't do
> > that with NHibernate. You'll need them to all be in the same table and call
> > DiscriminateSubclassesOnColumn in your ClassMap.
>
> > > > On Tue, Aug 18, 2009 at 8:42 PM, Mikael Henriksson <
> > [email protected]>wrote:
>
> > > >> I have many classes but only three is important for what I am trying
> > to
> > > >> do.
> > > >> Let's say I have a person:
> > > >>     public class Person
> > > >>     {
> > > >>         public virtual int Id { get; private set; }
> > > >>         public virtual string FirstName { get; set; }
> > > >>         public virtual string LastName { get; set; }
> > > >>     }
>
> > > >> Now I want to inherit from person because a *board member *is a
> > person.
> > > >> but I have different types of board members that I want to
> > discriminate on
> > > >> for instance Chairman that inherits from BoardMember:
> > > >>     public class BoardMember : Person
> > > >>     {
> > > >>         public virtual Board Board { get; set; }
> > > >>         public virtual MemberTypes Type { get; set; }
> > > >>     }
>
> > > >>     public class Chairman : BoardMember
> > > >>     {
>
> > > >>     }
>
> > > >> Now I thought I would do something like:
> > > >> public class PersonMap : ClassMap<Person>
> > > >>  {
> > > >> public PersonMap()
> > > >> {
> > > >>  Table("person");
> > > >> Id(x => x.Id, "person_id");
> > > >> Map(x => x.FirstName, "person_first_name");
> > > >>  Map(x => x.LastName, "person_last_name");
> > > >> }
> > > >> }
>
> > > >>     public class BoardMemberMap : SubclassMap<BoardMember>
> > > >>     {
> > > >>         public BoardMemberMap()
> > > >>         {
> > > >>             Table("board_member");
> > > >>             Map(x => x.Type).Column("board_member_type");
> > > >>             DiscriminateSubclassOnColumn("board_member_type");
> > > >>         }
> > > >>     }
>
> > > >>      public class Chairman : SubclassMap<Chairman>
> > > >>     {
> > > >>         public Chairman()
> > > >>         {
>
> > > >>         }
> > > >>     }
>
> > > >> However DiscriminateSubclassOnColumn is not available within
> > SubclassMap
> > > >> so how do I work around it? :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to