ObjectResult<T>.Dispose 메서드

정의

리소스 해제, 해제 또는 다시 설정과 관련된 작업을 수행합니다.

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

예제

이 예제에서는 ObjectResult<T> 메서드에서 반환합니다 Execute . 그런 다음 열거자를 가져오고 쿼리 결과를 반복합니다. 끝부분에서 열거자와 개체를 해제합니다 ObjectResult<T> .

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

설명

쿼리 결과를 DbDataReader포함하는 닫습니다.

적용 대상

추가 정보