0
我想要我的搜索从数据库中返回随机条目。如何执行此操作?
这是我的搜索功能,我正在使用Join查询并已采用新模型来传递属性。如何使用Linq从mvc4的数据库中获得随机条目
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());
可能重复http://stackoverflow.com/questions/648196/random-row-from-linq-to-sql) – Magnus 2014-10-05 10:34:27
[EF Code First:如何获得随机行](http://stackoverflow.com/questions/7781893/ef-code-first - 如何对获得随机-行) – 2014-10-05 11:30:41