NHibernate 查询 - 多对多 - 急切加载(twitter 风格的关注者/关注者)
我一直在优化我的一个查询......这是我的场景......
我有一个类似于 Twitter 的域,用户可以在其中关注其他用户。因此,这是我的用户模型的示例:
User
-> Followers (many-to-many users)
-> Following (many-to-many users)
我现在需要返回关注用户“XYZ”的用户的分页结果,但还需要急切加载数据来确定当前登录的用户是否正在关注返回的关注者。
因此,我需要以某种方式急切地加载此内容:user->followers->following
(也许使用过滤器来仅为当前用户获取following
数据)
是这样的甚至可以在 1 个查询中完成,还是需要执行 2 个单独的查询? 1 个查询返回关注者的分页数据,然后另一个查询指定带有返回 ID 的 IN 子句,以获取登录用户的以下数据。
保罗
I have come stuck in optimizing one of my queries...here is my scenario...
I have a domain simular to Twitter where a user can follow other users. So here is a sample of my User model:
User
-> Followers (many-to-many users)
-> Following (many-to-many users)
I now need to return a paged result of users following user 'XYZ', but also eager load data needed to determine if the currently logged in user is following the returned followers.
So somehow i need to eager load this: user->followers->following
(maybe with a filter to just fetch the following
data for the current user)
Is this even possible to do in 1 query, or will I need to perform 2 seperate queries?
1 query to return the paged data of followers, then another query specifying an IN clause with returned ID's to fetch the following data for logged in user.
Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要两个查询来获取数据,但您可以使用 NHibernate Futures 方法在一次行程中执行两个查询。
在你的场景中你会做类似的事情
You need two queries to get the data, but you can execute both queries in a single trip using the NHibernate Futures methods.
In your scenario you'd do something like