Gary Hall
Gary Hall

Reputation:

NHibernate - drilling down from the aggregrate root

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.

Upvotes: 0

Views: 163

Answers (1)

asgerhallas
asgerhallas

Reputation: 17734

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.

Upvotes: 1

Related Questions