zoukankan      html  css  js  c++  java
  • 【转】Entity Framework 学习积累

    转自:http://www.cnblogs.com/mbailing/archive/2012/07/16/2593368.html

    EF4.1/4.3 的一些使用小技巧

              (1)、多表关联查询的写法:

          var query = (from m in context.Dic_PropertyClassDef.Include("Dic_PropertyTypeDef")
                                 .Include("Dic_PropertyTypeDef.Dic_PropertyValueDef")
                                 .Include("Dic_PropertyTypeDef.Dic_PropertyOptValueDef")

                     这是一个多表关联查询的写法。可以不停的InCude下去。不过太复杂的业务建议还是用 sql或者存储过程更好些。

              (2)、EF4.1/4.3中的in语句:

                    var query = Entities.Where(p => ids.Contains(p.ID));
                      ids 是本句中是你传的id列,可以是数组,泛型(List<int>)

              (3)、EF中的分页

                     query.OrderByDescending(r => r.PropID).Skip(startRowIndex).Take(maximumRows).ToList();

                     startRowIndex是起始索引,maximumRows要查询的条数。比哪startRowIndex=0,maximumRows=10 ,就是要从0开始查找10条记录。

                     EF的分布必需要与OrderByDescending一起使用。

  • 相关阅读:
    mac os 基本命令
    一个程序员的郁闷吐槽
    域名那些事儿
    EventEmitter事件派发器
    Array类型的操作方法
    居中与垂直居中
    Web Storage —— 登录时记住密码
    字符串字符统计
    颜色字符串转换(正则)
    将字符串转换为驼峰格式
  • 原文地址:https://www.cnblogs.com/luckylei66/p/2594326.html
Copyright © 2011-2022 走看看