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

定義

指定されたマージ オプションを使用してオブジェクト クエリを実行します。Executes the object query with the specified merge option.

public:
 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

クエリの実行時に使用する MergeOptionThe 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 Modelに基づいています。This example is based on the AdventureWorks Sales Model. この例では、ObjectResult<T> メソッドから Execute を返します。The example returns an ObjectResult<T> from Execute method. 次に、列挙子を取得し、クエリ結果を反復処理します。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;
    try
    {
        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
        ((IDisposable)enumerator).Dispose();
    }
    finally
    {
        // Dispose the query results and the enumerator.
        if (queryResults != null)
        {
            queryResults.Dispose();
        }
        if (enumerator != null)
        {
            ((IDisposable)enumerator).Dispose();
        }
    }
}
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
    Try
        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()
    Finally
        ' Dispose the query results and the enumerator. 
        If queryResults IsNot Nothing Then
            queryResults.Dispose()
        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 解決、状態管理、および Change Tracking」を参照してください。For more information, see Identity Resolution, State Management, and Change Tracking.

適用対象

こちらもご覧ください