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)

C# 向IQueryable添加一个Include扩展方法的更多相关文章

  1. 给 string 添加一个 GetInputStream 扩展方法

    有时候,我们须要读取一些数据,而无论这数据来源于磁盘上的数据文件,还是来源于网络上的数据.于是.就有了以下的 StringExtensions.cs: using System; using Syst ...

  2. 添加一个js扩展方法

    String.prototype.repeatify=String.prototype.repeatify || function(times){ var str=''; for(var i=0;i& ...

  3. 给IConfiguration写一个GetAppSetting扩展方法

    给 IConfiguration 写一个 GetAppSetting 扩展方法 Intro 在 .net core 中,微软已经默认使用 appsettings.json 来代替 app.config ...

  4. Qt applendPlainText()/append() 多添加一个换行解决方法

    Qt applendPlainText()/append() 多添加一个换行解决方法 void ConsoleDialog::appendMessageToEditor(const QString & ...

  5. 一个利用扩展方法的实例:AttachDataExtensions

    扩展方法是C# 3.0(老赵对VB不熟)中最简单,也是最常用的语言特性之一.这是老赵自以为的一个简单却不失经典的实例: [AttributeUsage(AttributeTargets.All, Al ...

  6. 在 JavaScript 中,我们能为原始类型添加一个属性或方法吗?

    原始类型的方法 JavaScript 允许我们像使用对象一样使用原始类型(字符串,数字等).JavaScript 还提供了这样的调用方法.我们很快就会学习它们,但是首先我们将了解它的工作原理,毕竟原始 ...

  7. Entity Framework DbSet<T>之Include方法与IQueryable<T>扩展方法Include的使用

    Entity Framework使用Code First方式时,实体之间已经配置好关系,根据实际情况某些情况下需要同时获取导航属性,比如获取商品的同时需要获取分类属性(导航属性),或者基于优化方面考虑 ...

  8. 写一个针对IQueryable<T>的扩展方法支持动态排序

    所谓的动态排序是指支持任意字段.任意升序降序的排序.我们希望在客户端按如下格式写: localhost:8000/api/items?sort=titlelocalhost:8000/api/item ...

  9. C#扩展方法

    扩展方法使您能够向现有类型“添加”方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 扩展方法就相当于一个马甲,给一个现有类套上,就可以为这个类添加其他方法了. 马甲必须定义为stati ...

随机推荐

  1. [转]IPTABLES中SNAT和MASQUERADE的区别

    IPtables中可以灵活的做各种网络地址转换(NAT)网络地址转换主要有两种:SNAT和DNAT SNAT是source network address translation的缩写即源地址目标转换 ...

  2. poj1984 带权并查集(向量处理)

    Navigation Nightmare Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 5939   Accepted: 2 ...

  3. CodeForces 450B 矩阵

    A - Jzzhu and Sequences Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  4. 为简单而努力:Android封装类详解

    一.简单说明 1, IntentService IntentService继承自Service,并在其内部创建了工作线程,用来处理耗时操作,其中onHandleIntent方法就是在子线程执行的,我们 ...

  5. bzoj4401: 块的计数

    首先,块的大小确定的话,可以发现方案最多只有1种 然后就可以O(nsqrt(n))搞,不过会TLE 接着我们又发现,一个节点可以作一个块的根,当且仅当该节点的size能被块的大小整除 然后就可以O(n ...

  6. js 对象 copy 对象

    function clone(myObj) { if (typeof (myObj) != 'object') return myObj; if (myObj == null) return myOb ...

  7. 【BZOJ-1040】骑士 树形DP + 环套树 + DFS

    1040: [ZJOI2008]骑士 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3312  Solved: 1269[Submit][Status ...

  8. MVC重写DefaultModelBinder实现自定义模型绑定

    在编写前台页面的时候为了使url传递参数的简短,比如personId="1"  我们通过url传递成pid=1  那么在后台action方法接受的模型Person类 的属性为per ...

  9. HDU 5738 Eureka

    传送门 题目大意: 给出平面上的$n$个点,每个点有唯一的标号($\text{label}$),这$n$个标号的集合记作$S$,点可能重合.求满足下列条件的$S$的子集$T$的数目: 1. $|T|\ ...

  10. AngularJs $cacheFactory 缓存服务

    可能之前的api写的有些枯燥吧,因为不烧脑,不需要很多逻辑思维来做处理,那么之后的文章会有趣很多,慢慢的开始烧脑了,准备好大量脑细胞的死亡吧~   先来篇简单的缓存服务. 本文将api文档里的$cac ...