Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


ObjectQuery<T>.Execute(MergeOption) Method

Definition

Executes the object query with the specified merge option.

C#
public System.Data.Objects.ObjectResult<T> Execute(System.Data.Objects.MergeOption mergeOption);

Parameters

mergeOption
MergeOption

The MergeOption to use when executing the query. The default is AppendOnly.

Returns

An ObjectResult<T> that contains a collection of entity objects returned by the query.

Examples

This example returns an ObjectResult<T> from Execute method. Then it gets an enumerator and iterates through the query results. At the end it releases the enumerator and the ObjectResult<T> object.

C#
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();
        }
    }
}

Remarks

The default merge option for object queries is AppendOnly. For more information, see Identity Resolution, State Management, and Change Tracking.

Applies to

Termék Verziók
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also