【发布时间】:2012-03-28 22:38:29
【问题描述】:
我有这些实体:
public class BlogPost {
public virtual int Id { get; set; }
public virtual IList<Keyword> Keywords { get; set; }
public virtual IList<BlogComment> Comments { get; set; }
}
public class BlogComment {
public virtual int Id { get; set; }
public virtual BlogPost Post { get; set; }
}
public class Keyword {
public virtual int Id { get; set; }
public virtual IList<BlogPost> BlogPosts { get; set; }
}
我想通过Keywords 和 cmets-count 加载BlogPosts 的分页列表。所以我试试这个:
var entities = session.Query<BlogPost>()
.Where(t => t.Published)
.FetchMany(t => t.Keywords)
.OrderByDescending(t => t.UpdatedAt)
.Skip((pageNumber - 1) * pageSize).Take(pageSize)
.Select(t => new {
CommentsCount = t.Comments.Count(),
Post = t
})
.ToList();
但出现以下错误:
不支持指定的方法。
当我删除 .Skip((pageNumber - 1) * pageSize).Take(pageSize) 时,它会起作用!例如
var entities = session.Query<BlogPost>()
.Where(t => t.Published)
.FetchMany(t => t.Keywords)
.OrderByDescending(t => t.UpdatedAt)
// remove the below line
//.Skip((pageNumber - 1) * pageSize).Take(pageSize)
.Select(t => new {
CommentsCount = t.Comments.Count(),
Post = t
})
.ToList();
您有什么想法可以通过包含Keywords 来获取多个行吗?感谢您的任何建议。
我正在使用NHibernate 3.2 mapping by code。
【问题讨论】:
标签: nhibernate paging linq-to-nhibernate nhibernate-3 nhibernate-projections