ObjectResult<T>.Dispose 메서드

정의

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

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

예제

이 예제에서는 메서드에서 를 ObjectResult<T> 반환합니다 Execute . @FSHO2@그런 다음 열거자를 가져오고 쿼리 결과를 반복합니다. @FSHO2@끝으로 열거자와 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를 닫습니다.

적용 대상

추가 정보