ZeusTheTrueGod
unread,Jul 6, 2009, 9:02:49 AM7/6/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Fluent NHibernate
Hi
I have this hierarchy of classes
<code>
public class P
{
public int Id{get;set;}
}
public class C1:P{}
public abstract class C2:P{}
public class C21:C2
{
public C22 Parent { get; set; }
}
public class C22:C2
{
public List<C21> Items { get; set; }
}
</code>
It looks like conventions are not applied when I map this with
SubClass
<code>
public class Map:ClassMap<P>
{
public Map()
{
Id(x => x.Id);
DiscriminateSubClassesOnColumn("disc")
.SubClass<C1>("c1", MapC1)
.SubClass<C2>("c2", MapC2)
;
}
private void MapC1(SubClassPart<C1> mapping)
{
}
private void MapC2(SubClassPart<C2> mapping)
{
mapping.SubClass<C21>("c21", MapC21);
mapping.SubClass<C22>("c22", MapC22);
}
private void MapC21(SubClassPart<C21> mapping)
{
mapping.References(x => x.Parent);//!Convention on
DefaultForeignKey is Lost here
}
private void MapC22(SubClassPart<C22> mapping)
{
mapping.HasMany(x => x.Items);
}
}
</code>
Column name of Many-to-One is not set because convention is not
applied
Here is the reason:
DiscriminatorPart.cs line 38
mapping.ParentClass.AddSubclass(subclass.GetSubclassMapping());
classMap.AddSubclass(subclass); // HACK for conventions
SubclassPart.cs line 109
mapping.AddSubclass(subclass.GetSubclassMapping());
When I use a mapping for children conventions are applied with the
hack, but for children of children
no conventions are applied because SubclassPart does not applies
conventions recursively on it own subclasses
Part of xml mapping result -
<xml>
<subclass name="DomainMappingGenerator.SimpleTestFixture+C21,
DomainMappingGenerator, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" discriminator-value="c21">
<many-to-one name="Parent" column="" />
</subclass>
</xml>
I solved my problem with explicitly seting of foreign key in
mapping.References(x => x.Parent).Column("aaa")