QueryableExtensions.Include QueryableExtensions.Include QueryableExtensions.Include Method

Definition

Overloads

Include(IQueryable, String) Include(IQueryable, String) Include(IQueryable, String)

Specifies the related objects to include in the query results.

Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>) Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>) Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>)

Specifies the related objects to include in the query results.

Include<T>(IQueryable<T>, String) Include<T>(IQueryable<T>, String) Include<T>(IQueryable<T>, String)

Specifies the related objects to include in the query results.

Include(IQueryable, String) Include(IQueryable, String) Include(IQueryable, String)

Specifies the related objects to include in the query results.

public static System.Linq.IQueryable Include (this System.Linq.IQueryable source, string path);
static member Include : System.Linq.IQueryable * string -> System.Linq.IQueryable
<Extension()>
Public Function Include (source As IQueryable, path As String) As IQueryable

Parameters

source
IQueryable IQueryable IQueryable

The source IQueryable on which to call Include.

path
String String String

The dot-separated list of related objects to return in the query results.

Returns

A new IQueryable with the defined query path.

Remarks

This extension method calls the Include(String) method of the source IQueryable object, if such a method exists. If the source IQueryable does not have a matching method, then this method does nothing. The ObjectQuery, ObjectSet<TEntity>, DbQuery and DbSet types all have an appropriate Include method to call. Paths are all-inclusive. For example, if an include call indicates Include("Orders.OrderLines"), not only will OrderLines be included, but also Orders. When you call the Include method, the query path is only valid on the returned instance of the IQueryable. Other instances of IQueryable and the object context itself are not affected. Because the Include method returns the query object, you can call this method multiple times on an IQueryable to specify multiple paths for the query.

Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>) Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>) Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>)

Specifies the related objects to include in the query results.

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public static System.Linq.IQueryable<T> Include<T,TProperty> (this System.Linq.IQueryable<T> source, System.Linq.Expressions.Expression<Func<T,TProperty>> path);
static member Include : System.Linq.IQueryable<'T> * System.Linq.Expressions.Expression<Func<'T, 'Property>> -> System.Linq.IQueryable<'T>
<Extension()>
Public Function Include(Of T, TProperty) (source As IQueryable(Of T), path As Expression(Of Func(Of T, TProperty))) As IQueryable(Of T)

Type Parameters

T

The type of entity being queried.

TProperty

The type of navigation property being included.

Parameters

source
IQueryable<T>

The source IQueryable on which to call Include.

path
Expression<Func<T,TProperty>>

A lambda expression representing the path to include.

Returns

A new IQueryable<T> with the defined query path.

Remarks

The path expression must be composed of simple property access expressions together with calls to Select for

composing additional includes after including a collection proprty. Examples of possible include paths are:

To include a single reference: query.Include(e => e.Level1Reference)

To include a single collection: query.Include(e => e.Level1Collection)

To include a reference and then a reference one level down: query.Include(e => e.Level1Reference.Level2Reference)

To include a reference and then a collection one level down: query.Include(e => e.Level1Reference.Level2Collection)

To include a collection and then a reference one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference))

To include a collection and then a collection one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Collection))

To include a collection and then a reference one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference))

To include a collection and then a collection one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Collection))

To include a collection, a reference, and a reference two levels down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference.Level3Reference))

To include a collection, a collection, and a reference two levels down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Collection.Select(l2 => l2.Level3Reference)))

This extension method calls the Include(String) method of the source IQueryable object, if such a method exists.

If the source IQueryable does not have a matching method, then this method does nothing.

The Entity Framework ObjectQuery, ObjectSet, DbQuery, and DbSet types all have an appropriate Include method to call.

When you call the Include method, the query path is only valid on the returned instance of the IQueryable<T>. Other

instances of IQueryable<T> and the object context itself are not affected. Because the Include method returns the

query object, you can call this method multiple times on an IQueryable<T> to specify multiple paths for the query.

Include<T>(IQueryable<T>, String) Include<T>(IQueryable<T>, String) Include<T>(IQueryable<T>, String)

Specifies the related objects to include in the query results.

public static System.Linq.IQueryable<T> Include<T> (this System.Linq.IQueryable<T> source, string path);
static member Include : System.Linq.IQueryable<'T> * string -> System.Linq.IQueryable<'T>
<Extension()>
Public Function Include(Of T) (source As IQueryable(Of T), path As String) As IQueryable(Of T)

Type Parameters

T

The type of entity being queried.

Parameters

source
IQueryable<T>

The source IQueryable<T> on which to call Include.

path
String String String

The dot-separated list of related objects to return in the query results.

Returns

A new IQueryable<T> with the defined query path.

Remarks

This extension method calls the Include(String) method of the source IQueryable<T> object, if such a method exists. If the source IQueryable<T> does not have a matching method, then this method does nothing. The ObjectQuery<T>, ObjectSet<TEntity>, DbQuery<TResult> and DbSet<TEntity> types all have an appropriate Include method to call. Paths are all-inclusive. For example, if an include call indicates Include("Orders.OrderLines"), not only will OrderLines be included, but also Orders. When you call the Include method, the query path is only valid on the returned instance of the IQueryable<T>. Other instances of IQueryable<T> and the object context itself are not affected. Because the Include method returns the query object, you can call this method multiple times on an IQueryable<T> to specify multiple paths for the query.

Applies to