Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any commonly used implementations of IQueryable?

Tags:

c#

c#-4.0

I'm writing a unit test of a class. Several of the class's methods take IQueryable objects as parameters, and I want to mock the objects that are passed into those methods. Are there any collections built into C# that implement IQueryable? If not, how can I mock these objects?

like image 989
Kevin Avatar asked Jan 11 '13 00:01

Kevin


People also ask

Which is better IQueryable or IEnumerable?

So if you working with only in-memory data collection IEnumerable is a good choice but if you want to query data collection which is connected with database `IQueryable is a better choice as it reduces network traffic and uses the power of SQL language.

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.

What is IQueryable used for?

IQueryable is suitable for querying data from out-memory (like remote database, service) collections. While querying data from a database, IQueryable executes a "select query" on server-side with all filters. IQueryable is beneficial for LINQ to SQL queries.

When should I use IQueryable and IEnumerable using LINQ?

In LINQ to query data from database and collections, we use IEnumerable and IQueryable for data manipulation. IEnumerable is inherited by IQueryable, Hence IQueryable has all the features of IEnumerable and except this, it has its own features. Both have its own importance to query data and data manipulation.


1 Answers

Just use IEnumerable<T>.AsQueryable(). Use whatever IEnumerable<T> implementer you like.

like image 82
John Saunders Avatar answered Oct 05 '22 13:10

John Saunders