ObjectResult<T>.Dispose Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Performs tasks associated with freeing, releasing, or resetting resources.
public:
override void Dispose();
public override void Dispose ();
override this.Dispose : unit -> unit
Public Overrides Sub Dispose ()
Examples
This example returns an ObjectResult<T> from the Execute method. Then it gets an enumerator and iterates through the query results. 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();
}
}
}
Remarks
Closes the DbDataReader, which contains the results of the query.
Applies to
See also
Spolupráca s nami v službe GitHub
Zdroj tohto obsahu nájdete v službe GitHub, kde môžete vytvárať a skúmať problémy a žiadosti o prijatie zmien. Ďalšie informácie nájdete v našom sprievodcovi prispievateľom.