ObjectQuery<T>.Intersect(ObjectQuery<T>) 메서드

정의

다른 개체 쿼리에 있는 결과만 포함하여 쿼리 결과를 제한합니다.Limits the query results by including only the results that exist in another object query.

public:
 System::Data::Objects::ObjectQuery<T> ^ Intersect(System::Data::Objects::ObjectQuery<T> ^ query);
public System.Data.Objects.ObjectQuery<T> Intersect (System.Data.Objects.ObjectQuery<T> query);
member this.Intersect : System.Data.Objects.ObjectQuery<'T> -> System.Data.Objects.ObjectQuery<'T>
Public Function Intersect (query As ObjectQuery(Of T)) As ObjectQuery(Of T)

매개 변수

query
ObjectQuery<T>

쿼리에 포함할 결과를 나타내는 ObjectQuery<T>입니다.An ObjectQuery<T> that represents the results to include in the query.

반환

ObjectQuery<T>

원래 인스턴스에 지정된 query를 기반으로 INTERSECT가 적용된 것과 동일한 새 ObjectQuery<T> 인스턴스입니다.A new ObjectQuery<T> instance that is equivalent to the original instance with INTERSECT applied based on the specified query.

예외

query 매개 변수가 null 또는 빈 문자열인 경우The query parameter is null or is an empty string.

예제

이 항목의 예제는 Microsoft SQL Server 제품 샘플: 데이터베이스를 기반으로 합니다.The example in this topic is based on the Microsoft SQL Server Product Samples: Database. 이 예에서는 ObjectQuery<T> 두 개의 다른 쿼리 결과를 포함 하는 새 개체를 만듭니다.This example creates a new ObjectQuery<T> object that contains the results of two other queries.

int productID1 = 900;
int productID2 = 950;
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString = @"SELECT VALUE product
        FROM AdventureWorksEntities.Products
        AS product WHERE product.ProductID > @productID1";

    ObjectQuery<Product> productQuery =
        new ObjectQuery<Product>(queryString,
            context, MergeOption.NoTracking);

    string queryString2 = @"SELECT VALUE product
        FROM AdventureWorksEntities.Products
        AS product WHERE product.ProductID > @productID2";

    ObjectQuery<Product> productQuery2 =
        new ObjectQuery<Product>(queryString2,
            context, MergeOption.NoTracking);

    ObjectQuery<Product> productQuery3 =
        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.
    foreach (Product result in productQuery3)
    {
        Console.WriteLine("Product Name: {0}", result.ProductID);
    }
}
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

설명

포함 될 query 결과를 정의 하는 제공 된는 같은 형식 또는와 호환 되는 형식 이어야 합니다 ObjectQuery<T> .The supplied query that defines results to include must be of the same type or of a type that is compatible with the ObjectQuery<T>.

제공 된에 정의 된 매개 변수는 query 인스턴스에 정의 된 매개 변수와 병합 됩니다 ObjectQuery<T> .Parameters that are defined in the supplied query are merged with parameters that are defined in the ObjectQuery<T> instance. 매개 변수는 결합 된에서 고유 해야 합니다 ObjectParameterCollection .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.

결과 쿼리는 메서드가 호출 된 인스턴스에서 연결을 상속 합니다 ObjectQuery<T> Intersect .The resulting query inherits the connection from the ObjectQuery<T> instance on which the Intersect method was called.

적용 대상

추가 정보