UPDATED: This is totally wrong assumption. I retested it and sure enough I was mistaken. NHibernate generates SQL that will get all children rows to both Children Lists. Thank sirrocco for the comment. I think the better question is how we could do something like this work.
I modified the code a bit from Fluent NHibernate Examples in Wiki.
Model
public class Parent
{
public IList<Child> Children1 { get; set; }
public IList<Child> Children2 { get; set; }
}
public class Child
{}
Schema
table Parent (
ID int primary key
)
table Child (
ID int primary key,
ParentID int
)
Fluent Mapping
public class ParentMap : ClassMap<Parent>
{
public ParentMap()
{
HasMany<Child>(x => x.Children1);
HasMany<Child>(x => x.Children2);
}
}
As you can see, although the class Parent has two Children lists (i.e., Children1 and Children2), when they are mapped to the database tables, there is nothing in the table saying that which children row should be in Children1 or Children2 lists.
From database perspective, we know only which children row belongs to which parent but not which Children lists.
However, this seems to work correctly in NHibernate. Is there anything happening behind the scene?