EntityCollection<(Of <(TEntity>)>)..::.CreateSourceQuery Method
This page is specific to:.NET Framework Version:3.54.0
.NET Framework Class Library
EntityCollection<(Of <(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)
Syntax

'Usage

Dim instance As EntityCollection
Dim returnValue As ObjectQuery(Of TEntity)

returnValue = instance.CreateSourceQuery()

'Declaration

Public Function CreateSourceQuery As ObjectQuery(Of TEntity)

Return Value

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

ExceptionCondition
InvalidOperationException

When the object is in an Added state.

-or-

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

Remarks

This property is used to obtain a new instance of ObjectQuery<(Of <(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<(Of <(TEntity>)>) to enable you to bind only objects of a specific type. For more information, see Binding Objects to Controls (Entity Framework).

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 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<(Of <(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).

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5 SP1
See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View