【发布时间】:2012-04-17 04:46:55
【问题描述】:
我目前正在编写一个非常基本的在线论坛,我想检索一个包含分页帖子子集的线程。所以我的映射是:
<class name="Thread" table="ForumThreads">
<id name="Id">
<generator class="identity"></generator>
</id>
<property name="Title"></property>
<bag name="Posts">
<key column="ThreadID"></key>
<one-to-many class="Post"/>
</bag>
</class>
<class name="Post" table="ForumPosts">
<id name="Id">
<generator class="identity"></generator>
</id>
<property name="Content"></property>
<many-to-one name="Thread"
class="Thread"
column="ThreadID">
</many-to-one>
</class>
我想做这样的事情:
public class Thread
{
public virtual int Id { get; set; }
public virtual string Title { get; set; }
public virtual IEnumerable<Post> Posts { get; set; }
}
public class Post
{
public virtual int Id { get; set; }
public virtual Thread Thread { get; set; }
public virtual string Content { get; set; }
}
public Thread GetThread(int threadId, int page, int pageSize, out int count)
{
var session = SessionFactory.CurrentSession;
// Query to get the thread with a child collection of paged posts.
return thread;
}
是否可以用一个查询来做到这一点,还是我必须将它分成两个?
谢谢
【问题讨论】:
-
有一些关于这些 SO 问题的资源:@987654321@stackoverflow.com/q/4284438/654134
标签: nhibernate collections paging