QueryableExtensions.Include Method
Assembly: EntityFramework (in EntityFramework.dll)
Name | Description | |
---|---|---|
![]() ![]() | Include(IQueryable, String) | Specifies the related objects to include in the query results. |
![]() ![]() | Include<T>(IQueryable<T>, String) | Specifies the related objects to include in the query results. |
![]() ![]() | Include<T, TProperty>(IQueryable<T>, Expression<Func<T, TProperty>>) | Specifies the related objects to include in the query results. |
QueryableExtensions.Include Method (IQueryable, String)
Specifies the related objects to include in the query results.
Parameters
- source
-
Type:
System.Linq.IQueryable
The source IQueryable on which to call Include.
- path
-
Type:
System.String
The dot-separated list of related objects to return in the query results.
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.
QueryableExtensions.Include<T> Method (IQueryable<T>, String)
Specifies the related objects to include in the query results.
Parameters
- source
-
Type:
System.Linq.IQueryable<T>
The source IQueryable<T> on which to call Include.
- path
-
Type:
System.String
The dot-separated list of related objects to return in the query results.
Type Parameters
- T
The type of entity being queried.
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.
QueryableExtensions.Include<T, TProperty> Method (IQueryable<T>, Expression<Func<T, TProperty>>)
Specifies the related objects to include in the query results.
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public static IQueryable<T> Include<T, TProperty>( this IQueryable<T> source, Expression<Func<T, TProperty>> path )
Parameters
- source
-
Type:
System.Linq.IQueryable<T>
The source IQueryable on which to call Include.
- path
-
Type:
System.Linq.Expressions.Expression<Func<T, TProperty>>
A lambda expression representing the path to include.
Type Parameters
- T
The type of entity being queried.
- TProperty
The type of navigation property being included.
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 =&gt; e.Level1Reference) To include a single collection: query.Include(e =&gt; e.Level1Collection) To include a reference and then a reference one level down: query.Include(e =&gt; e.Level1Reference.Level2Reference) To include a reference and then a collection one level down: query.Include(e =&gt; e.Level1Reference.Level2Collection) To include a collection and then a reference one level down: query.Include(e =&gt; e.Level1Collection.Select(l1 =&gt; l1.Level2Reference)) To include a collection and then a collection one level down: query.Include(e =&gt; e.Level1Collection.Select(l1 =&gt; l1.Level2Collection)) To include a collection and then a reference one level down: query.Include(e =&gt; e.Level1Collection.Select(l1 =&gt; l1.Level2Reference)) To include a collection and then a collection one level down: query.Include(e =&gt; e.Level1Collection.Select(l1 =&gt; l1.Level2Collection)) To include a collection, a reference, and a reference two levels down: query.Include(e =&gt; e.Level1Collection.Select(l1 =&gt; l1.Level2Reference.Level3Reference)) To include a collection, a collection, and a reference two levels down: query.Include(e =&gt; e.Level1Collection.Select(l1 =&gt; l1.Level2Collection.Select(l2 =&gt; 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&lt;T&gt;. Other instances of IQueryable&lt;T&gt; 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&lt;T&gt; to specify multiple paths for the query.