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)
C# 向IQueryable添加一个Include扩展方法的更多相关文章
- 给 string 添加一个 GetInputStream 扩展方法
有时候,我们须要读取一些数据,而无论这数据来源于磁盘上的数据文件,还是来源于网络上的数据.于是.就有了以下的 StringExtensions.cs: using System; using Syst ...
- 添加一个js扩展方法
String.prototype.repeatify=String.prototype.repeatify || function(times){ var str=''; for(var i=0;i& ...
- 给IConfiguration写一个GetAppSetting扩展方法
给 IConfiguration 写一个 GetAppSetting 扩展方法 Intro 在 .net core 中,微软已经默认使用 appsettings.json 来代替 app.config ...
- Qt applendPlainText()/append() 多添加一个换行解决方法
Qt applendPlainText()/append() 多添加一个换行解决方法 void ConsoleDialog::appendMessageToEditor(const QString & ...
- 一个利用扩展方法的实例:AttachDataExtensions
扩展方法是C# 3.0(老赵对VB不熟)中最简单,也是最常用的语言特性之一.这是老赵自以为的一个简单却不失经典的实例: [AttributeUsage(AttributeTargets.All, Al ...
- 在 JavaScript 中,我们能为原始类型添加一个属性或方法吗?
原始类型的方法 JavaScript 允许我们像使用对象一样使用原始类型(字符串,数字等).JavaScript 还提供了这样的调用方法.我们很快就会学习它们,但是首先我们将了解它的工作原理,毕竟原始 ...
- Entity Framework DbSet<T>之Include方法与IQueryable<T>扩展方法Include的使用
Entity Framework使用Code First方式时,实体之间已经配置好关系,根据实际情况某些情况下需要同时获取导航属性,比如获取商品的同时需要获取分类属性(导航属性),或者基于优化方面考虑 ...
- 写一个针对IQueryable<T>的扩展方法支持动态排序
所谓的动态排序是指支持任意字段.任意升序降序的排序.我们希望在客户端按如下格式写: localhost:8000/api/items?sort=titlelocalhost:8000/api/item ...
- C#扩展方法
扩展方法使您能够向现有类型“添加”方法,而无需创建新的派生类型.重新编译或以其他方式修改原始类型. 扩展方法就相当于一个马甲,给一个现有类套上,就可以为这个类添加其他方法了. 马甲必须定义为stati ...
随机推荐
- 使用kuernetes提供高可用的logstash服务
在kubernetes集群中部署logstash步骤如下: 1:logstash安装文件(目前最新版本2.3.4): 2:编写Dockerfile及执行点脚本文件run.sh,并且修改logstash ...
- ubuntu安装pip3
当初入门Linux 使用的是centos,那个时候是6.0版本,当然现在主流在使用的也是6.0系列的,现在都到6.7了,那个时候centos还是独立的,现在被redhat收购,本来一个红蓝就差不多,个 ...
- 在Eclipse中如何关联spring-framework的文档和源代码
1.到官方网站去下载spring-framework的jar包 spring-framework jar包的下载地址是:http://repo.spring.io/release/org/spring ...
- 【poj3264】 Balanced Lineup
http://poj.org/problem?id=3264 (题目链接) 题意 给出序列,求区间最大值-最小值 Solution 无修改,询问较多,ST表水一发. ST算法(Sparse Table ...
- Azure 数据库中文乱码的问题
1,创建数据库的时候记得选择中文的 2,更新中文的时候记得加上N
- SQLite Learning、SQL Query Optimization In Multiple Rule
catalog . SQLite简介 . Sqlite安装 . SQLite Programing . SQLite statements 1. SQLite简介 SQLite是一款轻型的数据库,是遵 ...
- crawler: 常用的一些工具
phantomjs, Headless的WebKit Driver,意味着可以无需GUI,完全模拟Chrome/Safari的操作. casperjs(基于phantomjs的好用封装),zombie ...
- HFSS使用记录
一.基本设置 1.Tools \ Options,各种基本设置 1.1 Tools \ Options \ HFSS Options-> Duplicate boundaries/mesh op ...
- Process
--- - hosts: test gather_facts: false tasks: - name: Task1 shell: ls notify: Hander3 - name: Task2 s ...
- Unity 单例写法
借鉴自:http://www.cnblogs.com/CodeCabin/p/unity_global_manager.html 实现复杂一些的全局控制,如切换游戏关卡等操作,更常用的方式是使用单例类 ...