Reputation: 425
Problem:
I have the object hierarchy A => B => C
- that's A
references B
and B
references C
. C
contains the Name
property I'm trying to query on. I am trying to call the following code to get the list of A's
ICriteria criteria = session.CreateCriteria(typeof (A)).Add(Restrictions.Eq("B.C.Name", "Test"));
return criteria.List<A>();
I receive the error "Could not resolve property: B.C.Name of: A". All of my mappings look good whereby B
contains a C
property and C
contains a Name
property. I've also verified the mappings are correct because I'm running other queries that successfully retrieve the requested data.
Basically, I'm trying to get all the A's
that match the name in C
. So how do I write a query that can do this?
Thanks,
Kyle
Upvotes: 1
Views: 331
Reputation: 6726
Using QueryOver:
session.QueryOver<A>()
.JoinQueryOver(a => a.B)
.JoinQueryOver(b => b.C)
.Where(c => c.Name == "Test")
.List<A>();
You could also do it with aliases.
Upvotes: 2