以上您可以看到FollowingUsers
和StatusUpdates
表。
在FollowingUsers
中,我存储了Follower
的{{1}}和Username
的{{1}}。
在Following
中,我存储了Username
个用户。
下面你可以看到我写的原始查询来检索登录用户的状态更新。
StatusUpdates
如何从登录用户的关注状态获取状态更新?
答案 0 :(得分:2)
以下内容应该可行,但我没有您的数据库来测试它。请注意,在调用ToList之前实际上不会执行它,因此所有内容仍应在单个数据库查询中发生。此外,不需要创建新列表,因为它将被您的查询覆盖,所以我已经整理了一点。
var Users = from f in db.FollowingUsers
where f.FollowerId == User.Identity.Name
select f.FollowingId;
var list = (from x in db.StatusUpdates
from y in Users
where x.Author == y
orderby x.Timestamp descending
select x)
.Take(count).ToList();