ObjectQuery<T>.Execute(MergeOption) Metoda

Definice

Spustí dotaz objektu se zadanou možností sloučení.

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>
Public Function Execute (mergeOption As MergeOption) As ObjectResult(Of T)

Parametry

mergeOption
MergeOption

Parametr , MergeOption který se použije při provádění dotazu. Výchozí formát je AppendOnly.

Návraty

Obsahuje ObjectResult<T> kolekci objektů entity vrácených dotazem.

Příklady

Tento příklad vrátí metodu ObjectResult<T> from Execute . Pak získá enumerátor a iteruje výsledky dotazu. Na konci uvolní enumerátor a ObjectResult<T> objekt .

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

Poznámky

Výchozí možnost sloučení pro dotazy na objekty je AppendOnly. Další informace najdete v tématu Řešení identit, Správa stavu a Change Tracking.

Platí pro

Viz také