I am trying to solve the n+1 issue, where I retrieve all my forumthreads and posts. I tried to do it like the following:
return Session.Query<ForumThread>().Where(x => x.IsActive)
.OrderByDescending(x => x.LastForumPost)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.FetchMany(x=>x.ForumPosts)
.Cacheable();
But this gives an error:
Object does not match the destination type.
If I remove .Cacheable() it works. Is there any known error with fetching and using query caching?
I believe this was fixed in 3.1 (see https://nhibernate.jira.com/browse/NH-2502), although other bug numbers suggest otherwise.
If you’re not using 3.1, try upgrading.