zoukankan      html  css  js  c++  java
  • Entity Framework查询注意

     

      首先我们看下where的方法,直接查看定义(定义如下),其实一种是对IEnumerable的扩展,一种是对IQueryable的扩展,直接看最常用的,其实区别就在IEnumerable的扩展的参数是系统定义的委托Func<TSource,bool>

    IQueryable的参数则是表达式Expression<Func<TSource,bool>>,

    1。IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource,bool> predicate)

    2。IQueryable<TSource> Where<TSource>(this IQueryable<TSource> source, Expression<Func<TSource,bool>> predicate)

     

    先看看两个的使用,我只定义我没写具体委托和表达式的实现,大家自己根据需要写
    Func<QuestionFeed, bool> fun = null;

    //返回值类型为IEnumerable<T>
    db.Set<T>().Where<T>(fun) 

     

    Expression<Func<QuestionFeed, bool>> expression=null;
    //返回值为IQueryable<T>
    db.Set<T>().Where<T>(expression) 

     

    Func<T,bool>类型的便来那个如果作为参数传递给where方法进行Linq查询时,Entity FrameWork将会产生全表查询,将整个数据库表忠的数据加载到内存中,然后再内存中根据where中的条件进一步查询

    Expression<Func<t,bool>>只是查询出来你where条件中的数据,不用去进行全表查询

     

    EF的DbSet属性的Where方法默认是Expression<Func>,这就相当于微软建议我们使用db.Set<T>().Where<T>(expression) 这种方式。

     

    (相关信息:http://www.cnblogs.com/yjmyzz/archive/2009/02/19/1285564.html

    http://www.cnblogs.com/Gift/p/3549549.html

  • 相关阅读:
    python pandas groupby
    ORC 资料Mark
    python split() 用法
    Hive 中的变量
    特征选择方法
    Introduction to SIFT (Scale-Invariant Feature Transform)
    SIFT 、Hog 、LBP 了解
    python None 和 NaN
    判断特征中是否含有空值、空值填充
    vue 子组件引用
  • 原文地址:https://www.cnblogs.com/superCow/p/3783368.html
Copyright © 2011-2022 走看看