ObjectQuery<T>.Execute(MergeOption) ObjectQuery<T>.Execute(MergeOption) ObjectQuery<T>.Execute(MergeOption) Method


지정된 병합 옵션을 사용하여 개체 쿼리를 실행합니다.Executes the object query with the specified merge option.

 System::Data::Objects::ObjectResult<T> ^ Execute(System::Data::Objects::MergeOption mergeOption);
public System.Data.Objects.ObjectResult<T> Execute (System.Data.Objects.MergeOption mergeOption);
override this.Execute : System.Data.Objects.MergeOption -> System.Data.Objects.ObjectResult<'T>

매개 변수

MergeOption MergeOption MergeOption

쿼리를 실행할 때 사용할 MergeOption입니다.The MergeOption to use when executing the query. 기본값은 AppendOnly입니다.The default is AppendOnly.


쿼리에서 반환되는 엔터티 개체의 컬렉션을 포함하는 ObjectResult<T>입니다.An ObjectResult<T> that contains a collection of entity objects returned by the query.


이 예제는 기준으로 합니다 AdventureWorks Sales 모델합니다.This example is based on the AdventureWorks Sales Model. 예제에서는 ObjectResult<T> 메서드를 사용하여 Execute를 반환합니다.The example returns an ObjectResult<T> from Execute method. @FSHO2@그런 다음 열거자를 가져오고 쿼리 결과를 반복합니다.Then it gets an enumerator and iterates through the query results. 끝으로 열거자와 ObjectResult<T> 개체를 해제합니다.At the end it releases the enumerator and the ObjectResult<T> object.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
    ObjectSet<Product> query = context.Products;
    ObjectResult<Product> queryResults = null;

    System.Collections.IEnumerator enumerator = null;
        queryResults = query.Execute(MergeOption.AppendOnly);

        // Get the enumerator.
        enumerator = ((System.Collections.IEnumerable)queryResults).GetEnumerator();

        // Iterate through the query results.
        while (enumerator.MoveNext())
            Product product = (Product)enumerator.Current;
            Console.WriteLine("{0}", product.Name);
        // Dispose the enumerator
        // Dispose the query results and the enumerator.
        if (queryResults != null)
        if (enumerator != null)
Using context As New AdventureWorksEntities()
    Dim query As ObjectSet(Of Product) = context.Products
    Dim queryResults As ObjectResult(Of Product) = Nothing

    Dim enumerator As System.Collections.IEnumerator = Nothing
        queryResults = query.Execute(MergeOption.AppendOnly)

        ' Get the enumerator. 
        enumerator = DirectCast(queryResults, System.Collections.IEnumerable).GetEnumerator()

        ' Iterate through the query results. 
        While enumerator.MoveNext()
            Dim product As Product = DirectCast(enumerator.Current, Product)
            Console.WriteLine("{0}", product.Name)
        End While
        ' Dispose the enumerator 
        DirectCast(enumerator, IDisposable).Dispose()
        ' Dispose the query results and the enumerator. 
        If queryResults IsNot Nothing Then
        End If
        If enumerator IsNot Nothing Then
            DirectCast(enumerator, IDisposable).Dispose()
        End If
    End Try
End Using


개체 쿼리에 대한 기본 병합 옵션은 AppendOnly입니다.The default merge option for object queries is AppendOnly. 자세한 내용은 Id 확인, 상태 관리 및 변경 내용 추적합니다.For more information, see Identity Resolution, State Management, and Change Tracking.

적용 대상

추가 정보