zoukankan      html  css  js  c++  java
  • C# 向IQueryable添加一个Include扩展方法

    using System;
    using System.Data.Objects;
    using System.Linq;
    
    namespace OutOfMemory.Codes
    {
        /// <summary>
        /// Adds extension methods to the <see cref="IQueryable{T}"/> class.
        /// </summary>
        public static class QueryableExtender
        {
            /// <summary>
            /// Specifies the related objects to include in the query results.
            /// </summary>
            /// <typeparam name="T"><see cref="Type"/> of query to extend.</typeparam>
            /// <param name="this">The query to extend.</param>
            /// <param name="path">
            /// Dot-separated list of related objects to return in the query results.
            /// </param>
            /// <returns>
            /// A new <see cref="IQueryable{T}"/> with the defined query path.
            /// </returns>
            /// <exception cref="ArgumentNullException">
            /// The parameter <paramref name="path"/> is null.
            /// </exception>
            /// <exception cref="ArgumentException">
            /// The parameter <paramref name="path"/> is empty. 
            /// </exception>
            public static IQueryable<T> Include<T>(this IQueryable<T> @this, string path)
            {
                var objectQuery = @this as ObjectQuery<T>;
    
                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)

  • 相关阅读:
    使用SpringAOP
    Alpha 冲刺 (5/10)
    Alpha 冲刺 (4/10)
    Alpha 冲刺 (3/10)
    Alpha 冲刺 (2/10)
    Alpha 冲刺 (1/10)
    项目需求分析答辩总结
    项目UML设计(团队)
    项目选题报告答辩总结
    第七次作业--项目需求分析
  • 原文地址:https://www.cnblogs.com/shiningrise/p/5615556.html
Copyright © 2011-2022 走看看