0

I want my search to return Random entries from database.How to do this?
This is my search function where i am using Join query and have taken a new model to pass Attributes.

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());
2

1 Answer 1

2

By inserting the guid (which is random) the order with orderby would be random.:

  planetfeedsOrder.OrderBy(c => Guid.NewGuid()).Take(itemCount).ToList()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.