ObjectResult<T>.Dispose Metoda

Definicja

Wykonuje zadania związane z zwalnianiem, zwalnianiem lub resetowaniem zasobów.

public:
 override void Dispose();
public override void Dispose ();
override this.Dispose : unit -> unit
Public Overrides Sub Dispose ()

Przykłady

Ten przykład zwraca element ObjectResult<T> z Execute metody . Następnie pobiera moduł wyliczający i iteruje wyniki zapytania. Na końcu zwalnia moduł wyliczający i ObjectResult<T> obiekt .

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

Uwagi

Zamyka obiekt DbDataReader, który zawiera wyniki zapytania.

Dotyczy

Zobacz też