An entity with multiple Many-To-Many lists of the same type?

22 views
Skip to first unread message

Rob Gibbens

unread,
Dec 16, 2009, 3:16:55 PM12/16/09
to Fluent NHibernate
Does anybody know how I would map an entity with two many-to-many
collections of the same child type.
My database structure is this....
-----------------------------------------------------------------
The "normal" relationship will be....
tbl_Parent
col_Parent_ID
tbl_Parent_Child_Xref
col_Parent_ID
col_Child_ID
tbl_Child
col_Child_ID
-----------------------------------------------------------------
The alternative relationship is...
tbl_Parent
col_Parent_ID
tbl_Include_ParentChild_Xref
col_Parent_ID
col_Child_ID
tbl_Child
col_Child_ID
-----------------------------------------------------------------
The entity and mapping look like this...
public partial class ParentEntity : AuditableDataEntity<ParentEntity>
{
public virtual IList<ChildEntity> Children { get; set; }
public virtual IList<ChildEntity> IncludedChildren { get; set; }
}

public partial class ParentMap : IAutoMappingOverride<ParentEntity>
{
public void Override(AutoMapping<ParentEntity> mapping)
{
mapping.Table("tbl_Parent");
mapping.HasManyToMany(x => x.Children)
.Table("tbl_Parent_Child_Xref")
.ParentKeyColumn("col_Parent_ID")
.ChildKeyColumn("col_Child_ID")
.Inverse()
.Cascade.All();
mapping.HasManyToMany(x => x.IncludedChildren)
.Table("tbl_Include_ParentChild_Xref")
.ParentKeyColumn("col_Parent_ID")
.ChildKeyColumn("col_Child_ID")
.Inverse()
.Cascade.All();
}
}

---------------------------------------------------------------------------
---------------------------
The child entity and mapping look like this (just the opposite of the
parent)...


public partial class ChildEntity : AuditableDataEntity<ChildEntity>
{
public virtual IList<ParentEntity> Parents { get; set; }
public virtual IList<ParentEntity> IncludedParents { get; set; }
}

public partial class ChildMap : IAutoMappingOverride<ChildEntity>
{
public void Override(AutoMapping<ChildEntity> mapping)
{
mapping.Table("tbl_Child");
mapping.HasManyToMany(x => x.Parents)
.Table("tbl_Parent_Child_Xref")
.ParentKeyColumn("col_Child_ID")
.ChildKeyColumn("col_Parent_ID")
.Inverse()
.Cascade.All();
mapping.HasManyToMany(x => x.IncludedParents)
.Table("tbl_Include_ParentChild_Xref")
.ParentKeyColumn("col_Child_ID")
.ChildKeyColumn("col_Parent_ID")
.Inverse()
.Cascade.All();
}
}



-----------------------------------------------------------------
The error that I'm getting is
"System.NotSupportedException: Can't figure out what the other side
of
the many-to-many property 'Children' should be."

I'm using NHibernate 2.1.2, FluentNhibernate 1.0.

Rob Gibbens

unread,
Dec 16, 2009, 3:40:07 PM12/16/09
to Fluent NHibernate

Christian De Kievit

unread,
Dec 16, 2009, 5:00:25 PM12/16/09
to fluent-n...@googlegroups.com
Rob,

For starters, you should only specify Inverse() on one side of the relationship.  You need to figure out which side "owns" the relationship, and then use inverse() on the other side.  May not fix the problem, but you'll still need to do it.

Cheers,
Christian

2009/12/17 Rob Gibbens <robgi...@gmail.com>
--

You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.





--
Christian De Kievit

Paul Batum

unread,
Dec 16, 2009, 5:04:38 PM12/16/09
to fluent-n...@googlegroups.com
Ahh bugger, I guess that other thread is one of the hundred or so "I'll get back to it at some point" threads that I have starred in gmail. :(

Mattias Petter Johansson

unread,
Dec 17, 2009, 7:28:11 AM12/17/09
to Fluent NHibernate
So, this is not possible?

/mattias

On 16 Dec, 23:04, Paul Batum <paul.ba...@gmail.com> wrote:
> Ahh bugger, I guess that other thread is one of the hundred or so "I'll get
> back to it at some point" threads that I have starred in gmail. :(
>

> On Thu, Dec 17, 2009 at 9:00 AM, Christian De Kievit <cdekie...@gmail.com>wrote:
>
>
>
> > Rob,
>
> > For starters, you should only specify Inverse() on one side of the
> > relationship.  You need to figure out which side "owns" the relationship,
> > and then use inverse() on the other side.  May not fix the problem, but
> > you'll still need to do it.
>
> > Cheers,
> > Christian
>

> > 2009/12/17 Rob Gibbens <robgibb...@gmail.com>


>
> > I found this post, but I'm not sure if it was ever fixed.
>

> >>http://groups.google.com/group/fluent-nhibernate/browse_thread/thread...

> >> fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsubscr i...@googlegroups.com>


> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/fluent-nhibernate?hl=en.
>
> > --
> > Christian De Kievit
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Fluent NHibernate" group.
> > To post to this group, send email to fluent-n...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsubscr i...@googlegroups.com>

Rob Gibbens

unread,
Dec 17, 2009, 10:12:28 AM12/17/09
to Fluent NHibernate
Paul,
Were you still planning on adding that code, or should I get the
FNH source and add it? Is that still a valid solution (as far as you
know)?

On Dec 16, 5:04 pm, Paul Batum <paul.ba...@gmail.com> wrote:
> Ahh bugger, I guess that other thread is one of the hundred or so "I'll get
> back to it at some point" threads that I have starred in gmail. :(
>

> On Thu, Dec 17, 2009 at 9:00 AM, Christian De Kievit <cdekie...@gmail.com>wrote:
>
>
>
> > Rob,
>
> > For starters, you should only specify Inverse() on one side of the
> > relationship.  You need to figure out which side "owns" the relationship,
> > and then use inverse() on the other side.  May not fix the problem, but
> > you'll still need to do it.
>
> > Cheers,
> > Christian
>

> > 2009/12/17 Rob Gibbens <robgibb...@gmail.com>


>
> > I found this post, but I'm not sure if it was ever fixed.
>

> >>http://groups.google.com/group/fluent-nhibernate/browse_thread/thread...

> >> fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsubscr i...@googlegroups.com>


> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/fluent-nhibernate?hl=en.
>
> > --
> > Christian De Kievit
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Fluent NHibernate" group.
> > To post to this group, send email to fluent-n...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsubscr i...@googlegroups.com>

Paul Batum

unread,
Dec 17, 2009, 4:14:35 PM12/17/09
to fluent-n...@googlegroups.com
To be honest I'm not sure. I did want to take a look at this on the weekend. That said I think it would probably be in your best interests if you grab the FNH source, make the change and see if it resolves your issue. If you do it by creating a fork on github, even better :)

(just in case :) )

To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages