摘要

在使用ef做查询优化的时候我们会用到AsNoTracking方法,但如果不引入命名空间,你就会出现不包含“AsNoTracking”的定义的错误。

解决办法

引入命名空间:System.Data.Entity

AsNoTracking是对IQueryable的扩展,看它的定义就可以知道,代码片段如下:

  1. //
  2. // 摘要:
  3. // Returns a new query where the entities returned will not be cached in the
  4. // System.Data.Entity.DbContext or System.Data.Entity.Core.Objects.ObjectContext.
  5. // This method works by calling the AsNoTracking method of the underlying query
  6. // object. If the underlying query object does not have an AsNoTracking method,
  7. // then calling this method will have no affect.
  8. //
  9. // 参数:
  10. // source:
  11. // The source query.
  12. //
  13. // 类型参数:
  14. // T:
  15. // The element type.
  16. //
  17. // 返回结果:
  18. // A new query with NoTracking applied, or the source query if NoTracking is
  19. // not supported.
  20. public static IQueryable<T> AsNoTracking<T>(this IQueryable<T> source) where T : class;
  1. //
  2. // 摘要:
  3. // Returns a new query where the entities returned will not be cached in the
  4. // System.Data.Entity.DbContext or System.Data.Entity.Core.Objects.ObjectContext.
  5. // This method works by calling the AsNoTracking method of the underlying query
  6. // object. If the underlying query object does not have an AsNoTracking method,
  7. // then calling this method will have no affect.
  8. //
  9. // 参数:
  10. // source:
  11. // The source query.
  12. //
  13. // 返回结果:
  14. // A new query with NoTracking applied, or the source query if NoTracking is
  15. // not supported.
  16. public static IQueryable AsNoTracking(this IQueryable source);

[bug]不包含“AsNoTracking”的定义的更多相关文章

  1. C# dynamic类型报错:“object”不包含“xxx”的定义

    一.起因: 最近在做的一个项目,因为很多地方要用到同一套流程.为了后期维护,要求将共用流程进行抽离,创建为一个公用的类库.在抽离之前程序运行是没有问题的,然而在抽离之后就得到了如题错误: object ...

  2. 记dynamic的一个小坑 -- RuntimeBinderException:“object”未包含“xxx”的定义

    创建一个控制台程序和一个类库, 在控制台创建一个匿名对象,然后再在类库中访问它,代码如下: namespace ConsoleApplication1 { class Program { static ...

  3. 包含为 HTTP 定义的状态代码的值(枚举)

    using System; namespace System.Net { // 摘要: // 包含为 HTTP 定义的状态代码的值. public enum HttpStatusCode { // 摘 ...

  4. “IAsyncOperation<StorageFile>”不包含“GetAwaiter”的定义

    错误 CS4036 "IAsyncOperation<StorageFile>"不包含"GetAwaiter"的定义,并且找不到可接受类型为&quo ...

  5. <转>记dynamic的一个小坑 -- RuntimeBinderException:“object”未包含“xxx”的定义

    →转载地址← 创建一个控制台程序和一个类库, 在控制台创建一个匿名对象,然后再在类库中访问它,代码如下: namespace ConsoleApplication1 { class Program { ...

  6. 记dynamic的一个小坑 -- RuntimeBinderException:“object”未包含“xxx”的定义

    from:http://blog.csdn.net/feiyun0112/article/details/39697955 创建一个控制台程序和一个类库, 在控制台创建一个匿名对象,然后再在类库中访问 ...

  7. webAPI中“System.Web.Http.HttpConfiguration”不包含“EnableSystemDiagnosticsTracing”的定义解决办法

    webAPI中“System.Web.Http.HttpConfiguration”不包含“EnableSystemDiagnosticsTracing”的定义 今天从 运行 WebAPI 工程的代码 ...

  8. Xamarin.Android 开发,生成时提示“Resource.Drawable”未包含“BG”的定义

    Xamarin Android提示Resource.Drawable”未包含“BG”的定义错误信息:error CS0117: '“Resource.Drawable”未包含“BG”的定义Xamari ...

  9. 关于CS1061报错(XX不包含XXX的定义,并且找不到类型为XX的第一个参.....)的一种可能的解决的办法

    在我编程中,我遇到了一个这样的报错, 可是我引用的product类中又确实定义了这么一个方法, protected void BindPageData(int categoryID) { Produc ...

随机推荐

  1. EntityFramework Core 学习扫盲

    0. 写在前面 1. 建立运行环境 2. 添加实体和映射数据库 1. 准备工作 2. Data Annotations 3. Fluent Api 3. 包含和排除实体类型 1. Data Annot ...

  2. 深入探索AngularJS

    目录 深入探索AngularJS 作用域Scope是DOM和Directives交互的抽象 Scope是POJO对象 Scope是上下文 Scope继承树 Scope附加功能 正交功能 Element ...

  3. 实验6 LCD接口

    1.利用单片机控制LCD1602,在LCD1602上显示字符串,并使其整屏左移. #include<reg51.h> #define uchar unsigned char #define ...

  4. ip网段变更

    背景 公司网络跟集团靠拢,先走第一步:IP网段变更.从XX网段切换到OO网段 方法 1. 准备工作 a. 保证IPMI连接正常 b. 获得新IP并核对对应主机名.旧IP是否相符 2. 确认网卡名称 # ...

  5. linux常用命令(二)文件上传下载及软件安装

    1.上传下载工具安装 (1)WINDOWS 到linux的文件上传及下载: windows下打开secureCRT,通过SSH连到⾄至远程linux主机:上传下载工具安装命令:yum -y insta ...

  6. idea使用Protobuf插件

    1.protobuf简介 Protobuf是一个灵活的.高效的用于序列化数据的协议.相比较XML和JSON格式,protobuf更小.更快.更便捷.Protobuf是跨语言的,并且自带了一个编译器(p ...

  7. C#6.0语言规范(十四) 枚举

    一个枚举类型是一个独特的值类型(值类型)声明一组命名的常量. 这个例子 enum Color { Red, Green, Blue } 声明了一个名为枚举类型Color与成员Red,Green和Blu ...

  8. EF 通过修改模版 更改生成实体名称

    直接修改T4 模版中对应关系就可以了,我这里是去掉了表中的“_”

  9. Unity 代码编译成dll 更新dll实现热更代码

    Unity 代码编译成dll 更新dll实现热更代码 实现流程 代码编译成DLL DLL打包成AssetBundle 加载AssetBundle 加载代码程序集 获取指定类 使用反射赋值 C#代码编译 ...

  10. odoo开发笔记 -- 多个视图共用一个模型

    除了写序列优先绑定之外, 窗口引用的视图id也要绑定,否则页面加载的时候,可能不是自己需要显示的视图.例如:<field name="view_id" ref="c ...