ObjectQuery<T>.Distinct 메서드

정의

결과가 고유하도록 쿼리를 제한합니다.

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

반환

원래 인스턴스에 SELECT DISTINCT가 적용된 것과 동일한 새 ObjectQuery<T> 인스턴스입니다.

예제

이 예제에서는 메서드를 사용하여 UnionAllObjectQuery<T> 개체를 만듭니다. 그런 다음 새 ObjectQuery<T> 개체를 호출 Distinct 하여 이 쿼리의 고유한 결과를 가져옵니다.

int productID = 100;
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE product FROM AdventureWorksEntities.Products
            AS product WHERE product.ProductID < @productID";

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

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

    ObjectQuery<Product> productQuery3 =
        productQuery.UnionAll(productQuery2);

    productQuery3.Parameters.Add(new ObjectParameter("productID", productID));

    Console.WriteLine("Result of UnionAll");
    Console.WriteLine("------------------");

    // Iterate through the collection of Product items,
    // after the UnionAll method was called on two queries.
    foreach (Product result in productQuery3)
    {
        Console.WriteLine("Product Name: {0}", result.ProductID);
    }
    ObjectQuery<Product> productQuery4 = productQuery3.Distinct();

    Console.WriteLine("\nResult of Distinct");
    Console.WriteLine("------------------");

    // Iterate through the collection of Product items.
    // after the Distinct method was called on a query.
    foreach (Product result in productQuery4)
        Console.WriteLine("Product Name: {0}", result.ProductID);
}

설명

이 쿼리 작성기 메서드는 SELECT DISTINCT가 적용된 원래 쿼리와 동일한 instance 반환 ObjectQuery<T> 합니다.

연산자는 DISTINCT 데이터 원본의 비교할 수 없는 열(예: ntext)에 대한 매핑을 포함하는 개체에 적용할 수 없습니다.

적용 대상

추가 정보