Export (0) Print
Expand All

EntityCollection<TEntity>.CreateSourceQuery Method

Returns an object query that, when it is executed, returns the same set of objects that exists in the current collection.

Namespace:  System.Data.Objects.DataClasses
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public ObjectQuery<TEntity> CreateSourceQuery()

Return Value

Type: System.Data.Objects.ObjectQuery<TEntity>
An ObjectQuery<T> that represents the entity collection.


When the object is in an Added state.


When the object is in a Detached state with a MergeOption other than NoTracking.

This property is used to obtain a new instance of ObjectQuery<T> that returns the same set of objects. This is useful as the starting point for a more complex join, union, or filtered query, or to return the same objects in a detached state by using the NoTracking option.

CreateSourceQuery is used to filter objects in an EntityCollection<TEntity> to enable you to bind only objects of a specific type. For more information, see Binding Objects to Controls (Entity Framework).

This example is based on a modified version of the School model. This version supports table-per-type inheritance with Course as an abstract type. Complete the Mapping Inheritance - Table-per-Type walkthrough to modify the School model to support the table-per-type inheritance example used in this topic.

This example shows how to use CreateSourceQuery to filter objects in an EntityCollection<TEntity> and bind only to objects of a specific type. For a complete version of this example, see How to: Bind Controls to Derived Types (Entity Framework).

.NET Framework

Supported in: 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft