Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerable.Empty<T>() equivalent for IQueryable

People also ask

Which is better IEnumerable or IQueryable?

IEnumerable: IEnumerable is best suitable for working with in-memory collection (or local queries). IEnumerable doesn't move between items, it is forward only collection. IQueryable: IQueryable best suits for remote data source, like a database or web service (or remote queries).

What is the difference between returning IQueryable T vs IEnumerable T?

IEnumerable vs IQueryable The main difference between IEnumerable and IQueryable in C# is that IQueryable queries out-of-memory data stores, while IEnumerable queries in-memory data. Moreover, IQueryable is part of . NET's System. LINQ namespace, while IEnumerable is in System.

Does IEnumerable implement IQueryable?

The IQueryable interface inherits the IEnumerable interface so that if it represents a query, the results of that query can be enumerated. Enumeration causes the expression tree associated with an IQueryable object to be executed.

Is IQueryable faster than IEnumerable?

IQueryable is faster than IEnumerable. In addition to Munesh Sharma's answer:IEnumerable loads data in-memory and then apply filters to it one by one but IQueryable apply filters all at once and return the result.


Maybe:

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

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


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


Say you have an IQueryable<T> called result:

return result.Take(0);