我希望我的搜索从数据库中返回随机条目。如何做?。 这是我的搜索功能,我在使用Join查询并使用新模型传递属性。
var planetfeedsOrder = from a in db.PlanetFeeds
where a.PlanetFeedOwnerId == id || a.PlanetFeedPosterId == id
&& a.CurrentState != 1
join c in db.Graphs on a.PlanetFeedItemGraphId equals c.GraphID
join u in db.UserInfos on a.PlanetFeedOwnerId equals u.UserInfoID
orderby a.PostDate descending
select new UserInfoViewModel
{
AvatarURL = u.AvatarURL,
UserName=u.FirstName +" "+u.LastName,
GraphItemDescription = c.GraphItemDescription,
GraphItemURL = c.GraphItemURL,
isRootFeed = a.isRootFeed,
PostDate = a.PostDate,
CurrentState = a.CurrentState,
};
return PartialView("_PlanetfeedPartial",planetfeedsOrder.Take(itemCount).ToList());
答案 0 :(得分:2)
通过插入guid(随机),orderby的顺序是随机的。:
planetfeedsOrder.OrderBy(c => Guid.NewGuid()).Take(itemCount).ToList()