Export (0) Print
Expand All

ObjectQuery(Of T).Intersect Method

Limits the query results by including only the results that exist in another object query.

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

'Declaration
Public Function Intersect ( _
	query As ObjectQuery(Of T) _
) As ObjectQuery(Of T)

Parameters

query
Type: System.Data.Objects.ObjectQuery(Of T)
An ObjectQuery(Of T) that represents the results to include in the query.

Return Value

Type: System.Data.Objects.ObjectQuery(Of T)
A new ObjectQuery(Of T) instance that is equivalent to the original instance with INTERSECT applied based on the specified query.

ExceptionCondition
ArgumentNullException

The query parameter is Nothing or is an empty string.

The supplied query that defines results to include must be of the same type or of a type that is compatible with the ObjectQuery(Of T).

Parameters that are defined in the supplied query are merged with parameters that are defined in the ObjectQuery(Of T) instance. Parameters must be unique in the combined ObjectParameterCollection. There cannot be two parameters in the combined collection with the same name. For more information, see Query Builder Methods (Entity Framework).

The resulting query inherits the connection from the ObjectQuery(Of T) instance on which the Intersect method was called.

The example in this topic is based on the Adventure Works Sales Model. This example creates a new ObjectQuery(Of T) object that contains the results of two other queries.


Dim productID1 = 900
Dim productID2 = 950

Using context As New AdventureWorksEntities()
    Dim queryString As String = "SELECT VALUE product FROM AdventureWorksEntities.Products " & _
            " AS product WHERE product.ProductID > @productID1"

    Dim productQuery As New ObjectQuery(Of Product)(queryString, context, MergeOption.NoTracking)

    Dim queryString2 As String = "SELECT VALUE product FROM AdventureWorksEntities.Products " & _
        " AS product WHERE product.ProductID > @productID2"

    Dim productQuery2 As New ObjectQuery(Of Product)(queryString2, context, MergeOption.NoTracking)

    Dim productQuery3 As ObjectQuery(Of Product) = productQuery.Intersect(productQuery2)
    productQuery3.Parameters.Add(New ObjectParameter("productID1", productID1))
    productQuery3.Parameters.Add(New ObjectParameter("productID2", productID2))

    Console.WriteLine("Result of Intersect")
    Console.WriteLine("------------------")

    ' Iterate through the collection of Product items 
    ' after the Intersect method was called. 
    For Each result As Product In productQuery3
        Console.WriteLine("Product Name: {0}", result.ProductID)
    Next
End Using


.NET Framework

Supported in: 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft