The issue is here .Where(x => x.Actor.Age < 16 )
in the mapping
base.HasMany<FilmActor>(x => x.FilmChildActors).Where(x => x.Actor.Age < 16 );
This part is intended as a pure SQL Statement
.Where("SQL command") // or an boolean lambda expression
We can work there only with the content of the table containing the collection data. There is no way how to work with the Actor.Age
... just with the ActorId
.
But we can create a more complex SQL Statement, selecting those ActorIds, which are in some subselect
.Where("ActorId IN (SELECT a.ActorID FROM film_actor a ....
And in that case we can pass even some params like WHERE a.actor_id = actor_id
, where the second actor_id
is passed as param
For example check this QA How to Fluently map with constraint in HasMany
Also check the 6.2. Mapping a Collection, an extract:
where=""
(optional) specify an arbitrary SQL WHERE condition to be used when retrieving or removing the collection (useful if the collection should contain only a subset of the available data)