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 ...
随机推荐
- 查看本机ip
视窗+R 然后输入cmd, enter 后再黑色窗口里输入 ipconfig
- Ext-ajax请求数据
Ext.Ajax.request({ url: webPath+'/news/newsEastmoneyList', method: 'POST', success: function (respon ...
- Google Android 6.0 权限完全解析
注:本文只针对Google原生Android系统有效, 小米魅族等手机有自己的权限机制, 可能不适用 一.运行时权限的变化及特点 新的权限机制更好的保护了用户的隐私,Google将权限分为两类,一类是 ...
- 简进祥--iOS开发基础知识
1:App跳转至系统Settings 跳转在IOS8以上跟以下是有区别的,如果是IOS8以上可以如下设置: NSURL *url = [NSURL URLWithString:UIApplicatio ...
- 【BZOJ-3052】糖果公园 树上带修莫队算法
3052: [wc2013]糖果公园 Time Limit: 200 Sec Memory Limit: 512 MBSubmit: 883 Solved: 419[Submit][Status] ...
- 任意List 和DatabTable的转换
public static IEnumerable<T> ToEntityList<T>(this DataTable table) where T : class ...
- Windows Server 2012/2016在桌面上添加计算机等图标
[CMD]->输入[rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0],回车:
- ACM程序对拍
有时候在OJ刷题目的时候,总是会遇到不知名bug,题目总不能AC,自己测试的一些数据又都能得出正确的结果,又或是直接暴力会TLE,改了算法,但是仍然WA,这时候进行程序对拍测试数据不失为一个好办法.程 ...
- JSP+JavaBean+Servlet+Oracle新增功能中对Date类型的字段的处理
Oracle库中userinfo表borth字段是Date类型,age年纪字段是int类型.age字段要根据borth来自动计算 先说一下我遇到的问题: insert into的时候遇到日期转换类型错 ...
- cookie的实例
使得Cookie简化用户登陆,要求如下: 1.用户第一次登陆时需要输入用户名和密码 2.当登陆成功后,在Cookie中保存用户的登陆信息 3.设置Cookie有效期为5分钟 4.在有效期内用户再次登陆 ...