Is there an easy way to use QueryOver with nested properties?
For example, I try something like this;
// SPLAT!
session.QueryOver<SuperHero>().Where(Expression.Eq("HomeBase.Name", "Bat Cave");
It won't work because it 'could not resolve property 'homebase.name' of SuperHero. That makes sense, but there is obviously some way to make this work, because if I use the older 'Query' approach I can get it to work just fine, ie
// The results I (technically) want.
sess.Query<SuperHero>().Where(x => x.HomeBase.Name == "The Bat Cave");
So what am I missing? I am guessing that there is some way to combine expressions, etc. to get the nexted properties to work with QueryOver, but what are they?
You can't do a nested property access like that--you'll have to join to the related table:
session.QueryOver<SuperHero>()
.JoinQueryOver(sh => sh.HomeBase)
.Where(hb => hb.Name == "Bat Cave");
Also you don't need to use strings in your restrictions--that's one of the great advantages of using QueryOver after all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.