Queryable.AsQueryable Method (IEnumerable)

Converts an IEnumerable to an IQueryable.

Namespace:  System.Linq
Assemblies:   System.Linq.Queryable (in System.Linq.Queryable.dll)
  System.Core (in System.Core.dll)

public static IQueryable AsQueryable(
	this IEnumerable source
)

Parameters

source
Type: System.Collections.IEnumerable

A sequence to convert.

Return Value

Type: System.Linq.IQueryable
An IQueryable that represents the input sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

ExceptionCondition
ArgumentException

source does not implement IEnumerable<T> for some T.

ArgumentNullException

source is null.

If the type of source implements IQueryable<T>, AsQueryable(IEnumerable) returns it directly. Otherwise, it returns an IQueryable<T> that executes queries by calling the equivalent query operator methods in Enumerable instead of those in Queryable.

This method assumes that source implements IEnumerable<T> for some T. At runtime, the result is of type IQueryable<T> for the same T. This method is useful in dynamic scenarios when you do not statically know the type of T.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft