views:

153

answers:

3

When a method returns IEnumerable<T> and I do not have anything to return, we can use Enumerable.Empty<T>().

Is there an equivalent to the above for a method returning IQueryable<T>

A: 

Try return new T[0].AsQueryable();

alejandrobog
by "new T[0].AsQueryable();" we end up creating a new object of type T. :-(
System.ArgumentException
+2  A: 

Enumerable.Empty<T>().AsQueryable() should do it.

Josh Einstein
+6  A: 

Maybe:

Enumerable.Empty<T>().AsQueryable();

HTH.

Sunny
I know, currently that is the only simple, direct -) solution
System.ArgumentException