77

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

Is this possible?

dalle
  • 18,057
  • 5
  • 57
  • 81
Squirrel
  • 1,355
  • 2
  • 16
  • 25

2 Answers2

124
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
  • 16,398
  • 7
  • 76
  • 175
Paul van Brenk
  • 7,450
  • 2
  • 33
  • 38
  • 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
  • 15,207
  • 15
  • 92
  • 123
Chris Shaffer
  • 32,199
  • 5
  • 49
  • 61