I’m rather new to NHibernate, so this one should be easy:
public IList<Ad> Search(string query)
{
return unitOfWork.Session
.QueryOver<Ad>()
.JoinQueryOver<AdProperty>(x => x.Properties)
.Where(ad => ad.Value.Contains(query))
.List();
}
What I am trying to do, of course, is to search for Ads, where the AdProperty Contains a certain string, and pass back the corresponding Ad objects as a result. (I realize this will not result in an optimal query, but for now this will suffice)
The problem
I cannot use .Contains, as it is unrecognized. So how would I do this correctly with NHibernate ?
I’ve had a look at NHibernate query looking for the related object's related object, but I was unable to get that to function.
Note
I am using NHibernate 3.0+
After some more fiddling, I got the example (referenced above) to work. I will leave my solution for future reference for others.
Hope it helps someone 🙂