Hey. I have created an application in C#.net 3.5, using NHibernate!
To expose my problem, i have simplified the implemented domain model -> the following small class hierarchy should be enough to point out my problem!
BaseClass
Object : BaseClass
ObjectVariant : BaseClass
Document : Object
DocumentVariant : ObjectVariant
Document2 : Object
DocumentVariant2 : ObjectVariant
The class "Object" contains a collection of objects of type "ObjectVariant".
(
Code:
private ICollection<ObjectVariant> variants;
)
The persistent classes are "Object", "ObjectVariant", "Document", "Document2", "DocumentVariant", "DocumentVariant2"!
Therefore there are six tables in the database equivalent to these six classes!
And there are six mapping files, whereas the four classes starting with "Document" extend their base class!
Now I've following requirements regarding querying the database with the ICriteria API!
- query for "Object" including "ObjectVariant";
estimated result: all Objects, Documents and Documents2 including their Variants!
estimated tables in sql: all six tables!
actual: as estimated
- query for "Document" including "DocumentVariant";
estimated result: all Documents with it's DocumentVariants
estimated tables: Object, ObjectVariant, Document, DocumentVariant
actually used tables: Object, ObjectVariant, Document, DocumentVariant +
DocumentVariant2 reason: the "bag variants" is mapped in the mapping file for the class "Object" -> therefore NHibernate joins all possible Variants
problem: if I would map the "bag variants" in the derived class mappings and then query the base class including variants, the aliases for the different DocumentVariant tables would be the same in the sql query --> ADOException.
The outcome of this is following question: "Is it possible to 'override' the bag 'variants' in the derived mappings?"
Or is there any other way to achieve my requirements?
I would like to post a simple application including my problem, but it seems that this is not possible in this forum!
If someone can help me or is interessted in this problem, I could mail the small demo application!
Thanks in advance!