C# 向IQueryable添加一个Include扩展方法

using System;
using System.Data.Objects;
using System.Linq;

namespace OutOfMemory.Codes
{
    /// 
    /// Adds extension methods to the  class.
    /// 
    public static class QueryableExtender
    {
        /// 
        /// Specifies the related objects to include in the query results.
        /// 
        ///  of query to extend.
        /// The query to extend.
        /// 
        /// Dot-separated list of related objects to return in the query results.
        /// 
        /// 
        /// A new  with the defined query path.
        /// 
        /// 
        /// The parameter  is null.
        /// 
        /// 
        /// The parameter  is empty. 
        /// 
        public static IQueryable Include(this IQueryable @this, string path)
        {
            var objectQuery = @this as ObjectQuery;

            if (objectQuery != null)
            {
                return objectQuery.Include(path);
            }
            return @this;
        }
    }
}

 

DbExtensions.Include<T> Method (IQueryable<T>, String)

https://msdn.microsoft.com/en-us/library/system.data.entity.dbextensions.include

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

 

你可能感兴趣的:(C# 向IQueryable添加一个Include扩展方法)