views:

116

answers:

0

Class structure looks like the following:

abstract ItemBase - Discriminator [Type] = 0 [PrimaryKey GuidComb] Id
... shared properties

Item : ItemBase - [Type] = 1
[HasAndBelongsToMany, Inverse = true, RelationType = Set] -> Documents
... other properties

ItemHistory : ItemBase - [Type] = 2
[HasAndBelongsToMany, Inverse = false, RelationType = Set] -> Documents
... other properties

Document
[HasAndBelongsToMany, Inverse = false, RelationType = Set] -> Items
... other properties

The classes are in a Table-Per-Class-Heirarchy, with the following tables:
Item [Id, Type, ...]
DocumentItem [Document, Item]
Document [Id, ...]

The Problem
If I create an association entry for ItemHistory.Documents, the Document.Items collection loads it even though its not the mapped type.

So the Document.Items collection could look like this: [Item, ItemHistory, Item, Item, Item] which makes Item interface unusable for collection items.

I have it 'working' now but had to add a Where clause in the mapping that uses the NHibernate generated alias for the Item table: Where = "item1_.Type = 1"

Is there a better way to make this work?