HasMany() Collection of concrete Subclass

TDV's Avatar

TDV

08 Feb, 2011 04:03 PM via web

Hello, I have such business model:

table A (table per class)
ID
TYPE
REF_ID

abstract class A
{
ObjType { get; set; }
...
}
// ObjType = 'B'
class B : A
{
...
}
// ObjType = 'C'
class C : A
{
...
}
class D
{
IList<B> childs { get; set; }
...
}

Mapping for class A:
DiscriminateSubClassesOnColumn("TYPE");

Mapping for class B:
DiscriminatorValue("B")

Mapping for class C:
DiscriminatorValue("C")

Mapping for class D:
HasMany(x => x.childs)
                .KeyColumn("REF_ID")
                .Inverse()
                .Cascade.AllDeleteOrphan()
                .LazyLoad();

The problem is that sql for collection "childs" is generated with out condition on field "TYPE", something like that:
select * from A where ref_id = :param

But if I do session.Get<B>(id) everything goes fine.

I know it is possible to add "Where" clause to "HasMany" but it is not good idea on my mind.

Do someone the solution for this issue?

    Reply to this discussion

    Preview Comments are parsed with Markdown. Help with syntax

    Attached Files

      You can attach files up to 10MB

      What day comes after Monday?