2

I write this method :

 var resultVideos = (from video in db.Tbl_Videos
                            where channelName != "" ? video.Tbl_Categories.Tbl_Channels.Title.Equals(channelName) : true
                            select video)
                           .Where(video => categoryName != "" ? video.Tbl_Categories.Title.Equals(categoryName) : true)
                           .OrderBy(video => random.Next()).Take(8);

i know that provider can not convert them to expression tree, so i try this:

 .OrderBy(video => (int)random.Next()).Take(8);

But it doesn't work, what is the solution?

pmn
  • 2,176
  • 6
  • 29
  • 56
  • 1
    How would the EF provider translate an arbitrary method call into SQL? What SQL would you expect for this? If you just want a random order, see the possible duplicate. – Charles Mager May 11 '16 at 18:07
  • Try `.ToList().OrderBy(video => random.Next()).Take(8);` instead of `.OrderBy(video => random.Next()).Take(8);`. – Siyavash Hamdi May 11 '16 at 18:23

1 Answers1

0

Might be worth taking a look at the answers below:

To summarise it looks like you want to use OrderBy(video => Guid.NewGuid()) instead of OrderBy(video => rnd ). However, other users have said this causes filtering to be done client side so I'd keep that in mind!

Community
  • 1
  • 1