zoukankan      html  css  js  c++  java
  • ADO.Net Entity Framework Linq To Entities 语法功能汇编

    Linq To Entities 的语法基础可以参考:

    Microsoft Language Integrated Query (LINQ) 从入门到精通

    1.使用ObjectQuery类的ToTraceString()方法显示查询SQL语句

                 Console.WriteLine(customers.ToTraceString());

    2.基于表达式的查询语法

        ObjectQuery<Customers> customers = edm.Customers;

        IQueryable<Customers> cust1 = from c in customers

                                      where c.CustomerID == "ALFKI"

                                      select c;

    3.基于方法的查询语法

        var cust2 = edm.Customers.Where(c => c.CustomerID == "ALFKI");

    4.排序分页

    IQueryable<Customers> cust10 = (from c in customers

                                            orderby c.CustomerID

                                            select c).Skip(0).Take(10);

    或者

    var cust = edm.Customers.OrderBy(c => c.CustomerID).Skip(0).Take(10);

    5.可使用的聚合运算符有Average、Count、Max、Min 和 Sum。

          var maxuprice = edm.Products.Max(p => p.UnitPrice);

          Console.WriteLine(maxuprice.Value);

    6. 可以的连接有Join 和 GroupJoin 方法。GroupJoin组联接等效于左外部联接,它返回第一个(左侧)数据源的每个元素(即使其他数据源中没有关联元素)。

    using (var edm = new NorthwindEntities())

        {

          var query = from d in edm.Order_Details

                      join order in edm.Orders

                      on d.OrderID equals order.OrderID

                      select new

                        {

                            OrderId = order.OrderID,

                            ProductId = d.ProductID,

                            UnitPrice = d.UnitPrice

                        };

            foreach (var q in query)

            Console.WriteLine("{0},{1},{2}",q.OrderId,q.ProductId,q.UnitPrice);

    }

    参考文章:

    http://www.pin5i.com/showtopic-24045.html

    未完成!

    冯瑞涛
  • 相关阅读:
    SpringMVC(十六) 处理模型数据之SessionAttributes
    SpringBoot_web开发-【实验】-登陆&拦截器
    SpringBoot_web开发-【实验】-国际化
    SpringBoot_web开发-【实验】-引入资源
    什么是NIO?
    SpringBoot_web开发-扩展与全面接管SpringMVC
    SpringBoot_web开发-webjars&静态资源映射规则
    SpringBoot_web开发-thymeleaf语法
    SpringBoot_web开发-引入thymeleaf
    (实例)Linux 内核添加exfat驱动
  • 原文地址:https://www.cnblogs.com/finehappy/p/1680289.html
Copyright © 2011-2022 走看看