S
shapper
Hello,
To get a random record I am using the following:
context.Slides.Where(s => s.Active == true).ToList().GetRandom();
Where GetRandom is as follows:
public static class CollectionExtensions {
private static Random random = new Random();
public static T GetRandom<T>(this IList<T> list) {
if (list.Count == 0) return default(T);
return list[random.Next(0, list.Count)];
}
}
Wouldn't make more sense to have:
context.Slides.Where(s => s.Active == true).Random();
And is this even possible?
Thank You,
Miguel
To get a random record I am using the following:
context.Slides.Where(s => s.Active == true).ToList().GetRandom();
Where GetRandom is as follows:
public static class CollectionExtensions {
private static Random random = new Random();
public static T GetRandom<T>(this IList<T> list) {
if (list.Count == 0) return default(T);
return list[random.Next(0, list.Count)];
}
}
Wouldn't make more sense to have:
context.Slides.Where(s => s.Active == true).Random();
And is this even possible?
Thank You,
Miguel