75

I have an List and I'd like to wrap it into an IQueryable.

Is this possible?

dalle
  • 17,527
  • 5
  • 54
  • 78
Squirrel
  • 1,325
  • 2
  • 16
  • 25

2 Answers2

121
List<int> list = new List<int>() { 1, 2, 3, 4, };
IQueryable<int> query = list.AsQueryable();

If you don't see the AsQueryable() method, add a using statement for System.Linq.

user692942
  • 15,667
  • 7
  • 74
  • 164
Paul van Brenk
  • 7,260
  • 2
  • 32
  • 37
  • 1
    If you interested in the long way you could do: from q in query select q or list.Select(q => q) both would also get you an IQueryable – Nick Daniels Jan 24 '11 at 15:02
12

Use the AsQueryable<T>() extension method.

Chuck Norris
  • 14,646
  • 12
  • 87
  • 121
Chris Shaffer
  • 31,567
  • 5
  • 48
  • 61