views:

95

answers:

1

Given an aggregate root X, which has many Y, and Y which has many Z...

How can I drill down through the associations and select only those X's whose Z's have a certain property value?

IList Xs = Session.CreateCriteria(typeof(X)) .CreateAlias("Ys", "Y") .CreateAlias("Y.Zs", "Z") .Add(Expression.Eq("Z.Property", 1)) .List();

Doing this results in a PropertyAccessException, and I have no idea why.

Loading all Xs and testing their Z properties would be massively redundant.

+1  A: 

I have tried it out, and in my test setup it works flawlessly. A PropertyAccessExceotion can be about an unavailable setter or a type mismatch when a property is set. If you would post some mapping and entity souce code it might help.

asgerhallas