// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Infrastructure
{
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity.Internal;
using System.Data.Entity.Utilities;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
///
/// Represents a SQL query for non-entities that is created from a
/// and is executed using the connection from that context.
/// Instances of this class are obtained from the instance.
/// The query is not executed when this object is created; it is executed
/// each time it is enumerated, for example by using foreach.
/// SQL queries for entities are created using .
/// See for a generic version of this class.
///
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
[SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
public class DbRawSqlQuery : IEnumerable, IListSource
#if !NET40
, IDbAsyncEnumerable
#endif
{
#region Constructors and fields
private readonly InternalSqlQuery _internalQuery;
///
/// Initializes a new instance of the class.
///
/// The internal query.
internal DbRawSqlQuery(InternalSqlQuery internalQuery)
{
_internalQuery = internalQuery;
}
#endregion
#region AsStreaming
///
/// Returns a new query that will stream the results instead of buffering.
///
/// A new query with AsStreaming applied.
public DbRawSqlQuery AsStreaming()
{
return new DbRawSqlQuery(_internalQuery.AsStreaming());
}
#endregion
#region IEnumerable implementation
///
/// Returns an which when enumerated will execute the SQL query against the database.
///
///
/// An object that can be used to iterate through the elements.
///
public IEnumerator GetEnumerator()
{
return _internalQuery.GetEnumerator();
}
#endregion
#region IDbAsyncEnumerable implementation
#if !NET40
///
/// Returns an which when enumerated will execute the SQL query against the database.
///
///
/// An object that can be used to iterate through the elements.
///
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator()
{
return _internalQuery.GetAsyncEnumerator();
}
#endif
#endregion
#region Access to IDbAsyncEnumerable extensions
#if !NET40
public Task ForEachAsync(Action