Conceptually I want to map a collection like this:
HasMany(x => x.Children).Where("some_column_name='foo'");
The default mode of HasMany() requires me to provide a KeyColumn which should exist on the child table, and whose value should be the identifier value of the parent. But, I don't want to do that. I want to provide the only and entire sql clause for the join to this child table relationship.
Is it possible?
I tried leaving off the KeyColumn from the mapping entirely. But, nHibernate adds something to the generated sql by default -- it seems to be some kind of identifier placeholder for the parent class. For instance if the parent class of this relationship is called "Parent" then nH generates sql like
select .... from children child0_ where ([my custom where clause, yay]) and child0_.Parent_id=?
I want it to stop adding any additional clauses to this join and use ONLY my custom where clause provided by the .Where() method of the mapping.
I don't know the exact scenario so there might be an easier solution but this should work.
classes used
mapping
Testcode