C# DbQuery<;TResult>;实现IEnumerable<;TResult>;

C# DbQuery<;TResult>;实现IEnumerable<;TResult>;,c#,C#,我正在检查程序集EntityFramework.dll、v6.0.0.0、$EntityFramework.dll$v4.0.30319$NoDynamic\System.Data.Entity.Infrastructure.DbQuery.cs的元数据 using System; using System.Collections; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.L

我正在检查程序集EntityFramework.dll、v6.0.0.0、$EntityFramework.dll$v4.0.30319$NoDynamic\System.Data.Entity.Infrastructure.DbQuery.cs的元数据

using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace System.Data.Entity.Infrastructure
{
    // Summary:
    //     Represents a non-generic LINQ to Entities query against a DbContext.
    [SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
    public abstract class DbQuery : IOrderedQueryable, IQueryable, IEnumerable, IListSource, IDbAsyncEnumerable
    {
        // Summary:
        //     The IQueryable element type.
        public virtual Type ElementType { get; }

        // Summary:
        //     Returns a new query where the entities returned will not be cached in the
        //     System.Data.Entity.DbContext.
        //
        // Returns:
        //     A new query with NoTracking applied.
        public virtual DbQuery AsNoTracking();
        //
        // Summary:
        //     Returns a new query that will stream the results instead of buffering.
        //
        // Returns:
        //     A new query with AsStreaming applied.
        [Obsolete("Queries are now streaming by default unless a retrying ExecutionStrategy is used. Calling this method will have no effect.")]
        public virtual DbQuery AsStreaming();
        //
        // Summary:
        //     Returns the equivalent generic System.Data.Entity.Infrastructure.DbQuery<TResult>
        //     object.
        //
        // Type parameters:
        //   TElement:
        //     The type of element for which the query was created.
        //
        // Returns:
        //     The generic set object.
        public DbQuery<TElement> Cast<TElement>();
        //
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override bool Equals(object obj);
        //
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override int GetHashCode();
        //
        [EditorBrowsable(EditorBrowsableState.Never)]
        [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public Type GetType();
        //
        // Summary:
        //     Specifies the related objects to include in the query results.
        //
        // Parameters:
        //   path:
        //     The dot-separated list of related objects to return in the query results.
        //
        // Returns:
        //     A new DbQuery<T> with the defined query path.
        //
        // Remarks:
        //     Paths are all-inclusive. For example, if an include call indicates Include("Orders.OrderLines"),
        //     not only will OrderLines be included, but also Orders. When you call the
        //     Include method, the query path is only valid on the returned instance of
        //     the DbQuery<T>. Other instances of DbQuery<T> and the object context itself
        //     are not affected.  Because the Include method returns the query object, you
        //     can call this method multiple times on an DbQuery<T> to specify multiple
        //     paths for the query.
        public virtual DbQuery Include(string path);
        //
        // Summary:
        //     Returns a System.String representation of the underlying query.
        //
        // Returns:
        //     The query string.
        public override string ToString();
    }
}
使用系统;
使用系统集合;
使用系统组件模型;
使用System.Diagnostics.CodeAnalysis;
使用System.Linq;
命名空间System.Data.Entity.Infrastructure
{
//总结:
//表示针对DbContext的非泛型LINQ到实体查询。
[SuppressMessage(“Microsoft.Design”、“CA1010:CollectionsShouldImplementGenericInterface”)]
[SuppressMessage(“Microsoft.Naming”、“CA1710:IdentifiersShouldHaveCorrectSuffix”)]
公共抽象类DbQuery:IOrderedQueryable、IQueryable、IEnumerable、IListSource、IDbAsyncEnumerable
{
//总结:
//IQueryable元素类型。
公共虚拟类型ElementType{get;}
//总结:
//返回一个新查询,其中返回的实体不会缓存在
//System.Data.Entity.DbContext。
//
//返回:
//应用了NoTracking的新查询。
公共虚拟数据库查询AsNoTracking();
//
//总结:
//返回一个新查询,该查询将对结果进行流式处理,而不是缓冲。
//
//返回:
//已应用具有关联的新查询。
[过时(“除非使用重试执行策略,否则查询现在默认为流式处理。调用此方法将无效。”)]
公共虚拟数据库查询关联();
//
//总结:
//返回等效的泛型System.Data.Entity.Infrastructure.DbQuery
//反对。
//
//类型参数:
//远程服务:
//为其创建查询的元素的类型。
//
//返回:
//泛型集合对象。
公共DbQuery Cast();
//
[EditorBrowsable(EditorBrowsableState.Never)]
公共覆盖布尔等于(对象obj);
//
[EditorBrowsable(EditorBrowsableState.Never)]
公共覆盖int GetHashCode();
//
[EditorBrowsable(EditorBrowsableState.Never)]
[SuppressMessage(“Microsoft.Design”,“CA1024:UseProperties where appropriate”)]
公共类型GetType();
//
//总结:
//指定要包含在查询结果中的相关对象。
//
//参数:
//路径:
//要在查询结果中返回的相关对象的点分隔列表。
//
//返回:
//具有已定义查询路径的新DbQuery。
//
//备注:
//路径是全包的。例如,如果include调用指示include(“Orders.OrderLines”),
//不仅包括订单行,还包括订单
//方法,则查询路径仅对的返回实例有效
//DbQuery.DbQuery的其他实例和对象上下文本身
//不受影响。因为Include方法返回查询对象,所以
//可以对DbQuery多次调用此方法以指定多个
//查询的路径。
公共虚拟数据库查询包括(字符串路径);
//
//总结:
//返回基础查询的System.String表示形式。
//
//返回:
//查询字符串。
公共重写字符串ToString();
}
}

但是我没有找到GetEnumerator()方法。这是如何发生的?

从Mono和实际的EF6源代码来看,它显式地实现了该功能


它是显式实现的。。。从:

#区域IEnumerable
/// 
///返回枚举时将对数据库执行查询的。
/// 
///查询结果。
[SuppressMessage(“Microsoft.Design”、“CA1033:InterfaceMethods应可通过ChildTypes调用”)]
IEnumerator IEnumerable.GetEnumerator()
{
...
}
/// 
///返回枚举时将对数据库执行查询的。
/// 
///查询结果。
[SuppressMessage(“Microsoft.Design”、“CA1033:InterfaceMethods应可通过ChildTypes调用”)]
IEnumerator IEnumerable.GetEnumerator()
{
...
}
#端区

啊。。。请注意。。。您正在查看错误的文件<代码>我正在检查程序集EntityFramework.dll的元数据,v6.0.0.0,$EntityFramework.dll$v4.0.30319$NoDynamic\System.Data.Entity.Infrastructure.**DbQuery.cs**用于
抽象类DbQuery
,而不是
类DbQuery
。作为一个
抽象类
,它可能不完整(不能实现所有接口)。您应该查看DbQuery`.cs文件

谢谢。虽然链接确实证明它已经实现,但您解释了为什么我没有看到它。
#region IEnumerable

/// <summary>
/// Returns an <see cref="IEnumerator{TElement}" /> which when enumerated will execute the query against the database.
/// </summary>
/// <returns> The query results. </returns>
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
IEnumerator<TResult> IEnumerable<TResult>.GetEnumerator()
{
    ...
}

/// <summary>
/// Returns an <see cref="IEnumerator{TElement}" /> which when enumerated will execute the query against the database.
/// </summary>
/// <returns> The query results. </returns>
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
IEnumerator IEnumerable.GetEnumerator()
{
    ...
}

#endregion