Uredi

Deli z drugimi prek


EntityCollection<TEntity>.CreateSourceQuery Method

Definition

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

public:
 System::Data::Objects::ObjectQuery<TEntity> ^ CreateSourceQuery();
public System.Data.Objects.ObjectQuery<TEntity> CreateSourceQuery ();
override this.CreateSourceQuery : unit -> System.Data.Objects.ObjectQuery<'Entity (requires 'Entity : null and 'Entity :> System.Data.Objects.DataClasses.IEntityWithRelationships)>
override this.CreateSourceQuery : unit -> System.Data.Objects.ObjectQuery<'Entity (requires 'Entity : null)>
Public Function CreateSourceQuery () As ObjectQuery(Of TEntity)

Returns

ObjectQuery<TEntity>

An ObjectQuery<T> that represents the entity collection.

Exceptions

When the object is in an Added state.

-or-

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

Examples

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 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.

Remarks

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.

Applies to