Questions tagged [iqueryable]

.NET Framework Interface, providing functionality to evaluate queries against a specific data source wherein the type of the data is not specified.

The IQueryable interface is intended for implementation by query providers. It is only supposed to be implemented by providers that also implement IQueryable(Of T). If the provider does not also implement IQueryable(Of T), the standard query operators cannot be used on the provider's data source.

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. The definition of "executing an expression tree" is specific to a query provider. For example, it may involve translating the expression tree to an appropriate query language for the underlying data source. Queries that do not return enumerable results are executed when the Execute method is called.

http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspx

1457 questions
1211
votes
14 answers

Returning IEnumerable vs. IQueryable

What is the difference between returning IQueryable vs. IEnumerable, when should one be preferred over the other? IQueryable custs = from c in db.Customers where c.City == "" select c; IEnumerable custs = from c in…
stackoverflowuser
  • 22,212
  • 29
  • 67
  • 92
744
votes
24 answers

Dynamic LINQ OrderBy on IEnumerable / IQueryable

I found an example in the VS2008 Examples for Dynamic LINQ that allows you to use a SQL-like string (e.g. OrderBy("Name, Age DESC")) for ordering. Unfortunately, the method included only works on IQueryable. Is there any way to get this…
John Sheehan
  • 77,456
  • 30
  • 160
  • 194
474
votes
12 answers

What is the difference between IQueryable and IEnumerable?

What is the difference between IQueryable and IEnumerable? See also What's the difference between IQueryable and IEnumerable that overlaps with this question.
Nirmal
284
votes
4 answers

Using IQueryable with Linq

What is the use of IQueryable in the context of LINQ? Is it used for developing extension methods or any other purpose?
user190560
  • 3,459
  • 4
  • 20
  • 15
158
votes
6 answers

What's the difference between IQueryable and IEnumerable

I'm confused as to the difference. Being fairly new to .Net, I know I can query IEnumerables using the Linq extensions. So what is this IQueryable and how does it differ? See also What is the difference between IQueryable[T] and IEnumerable[T]?…
James Hay
  • 12,580
  • 8
  • 44
  • 67
140
votes
6 answers

Enumerable.Empty() equivalent for IQueryable

When a method returns IEnumerable and I do not have anything to return, we can use Enumerable.Empty(). Is there an equivalent to the above for a method returning IQueryable
Numan
  • 3,918
  • 4
  • 27
  • 44
131
votes
5 answers

What is the purpose of AsQueryable()?

Is the purpose of AsQueryable() just so you can pass around an IEnumerable to methods that might expect IQueryable, or is there a useful reason to represent IEnumerable as IQueryable? For example, is it supposed to be for cases like…
Ocelot20
  • 10,510
  • 11
  • 55
  • 96
99
votes
3 answers

Is there a C# LINQ syntax for the Queryable.SelectMany() method?

When writing a query using C# LINQ syntax, is there a way to use the Queryable.SelectMany method from the keyword syntax? For string[] text = { "Albert was here", "Burke slept late", "Connor is happy" }; Using…
BrianCooksey
  • 1,543
  • 1
  • 12
  • 19
94
votes
6 answers

Instantiate empty IQueryable for use with Linq to sql

I need to be able to either have an optional parameter in a Linq query, or be able to assign the query to a var in something like an IF if that optional parameter needs to be removed from the query. If I set the query var inside the IF statement…
user2073077
  • 977
  • 1
  • 7
  • 7
77
votes
2 answers

IList to IQueryable

I have an List and I'd like to wrap it into an IQueryable. Is this possible?
Squirrel
  • 1,355
  • 2
  • 16
  • 25
74
votes
3 answers

To return IQueryable or not return IQueryable

I have a repository class that wraps my LINQ to SQL Data Context. The repository class is a business line class that contains all the data tier logic (and caching and such). Here's my v1 of my repo interface. public interface ILocationRepository { …
CVertex
  • 17,997
  • 28
  • 94
  • 124
73
votes
3 answers

Differences between IQueryable, List, IEnumerator?

I am wondering what the difference between IQueryable, List, IEnumerator is and when I should use each one? For instance when using Linq to SQL I would do something like this: public List GetUsers() { return db.User.where(/* some query here…
chobo2
  • 83,322
  • 195
  • 530
  • 832
67
votes
5 answers

Convert IQueryable<> type object to List type?

I have IQueryable<> object. I want to Convert it into List<> with selected columns like new { ID = s.ID, Name = s.Name }. Edited Marc you are absolutely right! but I have only access to FindByAll() Method (because of my architecture). And it gives…
Vikas
  • 24,082
  • 37
  • 117
  • 159
67
votes
3 answers

How to merge two IQueryable lists

I want to merge the records of two IQueryable lists in C#. I try IQueryable list1 = values; IQueryable list2 = values1; obj.Concat(obj1); and IQueryable list1 = values; IQueryable list2 =…
Fraz Sundal
  • 10,288
  • 22
  • 81
  • 132
62
votes
5 answers

Why use AsQueryable() instead of List()?

I'm getting into using the Repository Pattern for data access with the Entity Framework and LINQ as the underpinning of implementation of the non-Test Repository. Most samples I see return AsQueryable() when the call returns N records instead of…
Keith Adler
  • 20,880
  • 28
  • 119
  • 189
1
2 3
97 98