Pardon my noobishness as I may often use the wrong terminology in
trying to describe my issue but several hours of searching is leaving
me empty-handed. I am using NHibernate with Fluent NHibernate for
mapping.

In my database I have a one to many relationship. I always see this
represented in a domain model where the parent entity has an
IList<child> property and mapping that works quite nicely. In my
particular case however, I need the ability to introduce a class in
the middle which contains the list of children so that my classes
would look something like:

class A
{
     public virtual long Id { get; set; }
     public virtual B Group { get; set; }
}

class B
{
     public virtual IList<C> Children { get; set; }
}

class C
{
     public virtual long Id { get; set; }
}

I've been able to generate schema and even persist but the
relationship is not preserved so that the child row's FK to the parent
ID is actually NULL. Here's what I was trying to cobble together for
my fluent maps:

public class AMap: ClassMap<A>
{
     public AMap()
     {
          Id(x => x.Id).GeneratedBy.Identity();
          Component(
               x => x.Group,
               y => y.HasMany(x => x.Children)
                         .KeyColumn("AId")
                         .AsBag()
                         .Cascade.All());
     }
}

public class CMap: ClassMap<C>
{
     public CMap()
     {
          Id(x => x.Id).GeneratedBy.Identity();
     }
}

I'm not sure what else to do at this point. Because I am potentially
missing some fundamentals or don't know the proper terminology, I've
been unable to find any examples of this anywhere. I was hoping since
NH generally does such a great job at allowing you to map the domain
to schema that I could accomplish this without altering the schema and
adding an additional table.

Thanks in advance,
Alex

--

You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.


Reply via email to