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

Definición

Ejecuta la consulta de objeto con la opción de combinación especificada.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>

Parámetros

mergeOption
MergeOption MergeOption MergeOption

MergeOption que se va a utilizar al ejecutar la consulta.The MergeOption to use when executing the query. De manera predeterminada, es AppendOnly.The default is AppendOnly.

Devoluciones

Un objeto ObjectResult<T> que contiene una colección de objetos entidad devueltos por la consulta.An ObjectResult<T> that contains a collection of entity objects returned by the query.

Ejemplos

En este ejemplo se basa en el modelo AdventureWorks Sales.This example is based on the AdventureWorks Sales Model. El ejemplo devuelve un ObjectResult<T> a partir de un método Execute.The example returns an ObjectResult<T> from Execute method. A continuación, obtiene un enumerador y recorre en iteración los resultados de la consulta.Then it gets an enumerator and iterates through the query results. Por último, libera el enumerador y el objeto 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

Comentarios

La opción de fusión mediante combinación predeterminada para las consultas de objeto es AppendOnly.The default merge option for object queries is AppendOnly. Para obtener más información, consulte resolución de identidades, administración de Estados y seguimiento de cambios.For more information, see Identity Resolution, State Management, and Change Tracking.

Se aplica a

Consulte también: