zoukankan      html  css  js  c++  java
  • LinQ

    用于获取数据源
    var queryAllCustomers=from cust in Customers select cust;
    需求:查询出成绩有90分以上的学生,得到他们的名字和成绩
    //数据源
    IList<Student> students = new List<Student>
    {
    new Student{ Name="Kevin", Score=new List<int>{89,93,88,78}},
    new Student{ Name="Jackie",Score=new List<int>{92,87,83,91}},
    new Student{ Name="Helen",Score=new List<int>{53,76,72,62}}
    };
    //使用复合from子句查询命令
    var getStudent =
    from student in students
    from score in student.Score
    where score > 90
    select new { Name=student.Name,Score=score};

    使用where筛选在伦敦的客户
    var q =
    from c in db.Customers
    where c.City == "London"
    select c;

    再如:筛选1994 年或之后雇用的雇员:
    var q =
    from e in db.Employees
    where e.HireDate >= new DateTime(1994, 1, 1)
    select e;

    筛选库存量在订货点水平之下但未断货的产品
    var q =
    from p in db.Products
    where p.UnitPrice > 10m || p.Discontinued
    select p;

    First()形式: 返回集合中的一个元素,其实质就是在SQL语句中加TOP (1)
    Shipper shipper = db.Shippers.First();
    元素:选择CustomerID 为“BONAP”的单个客户
    Customer cust = db.Customers.First(c => c.CustomerID == "BONAP");
    条件:选择运费大于 10.00 的订单:

    Order ord = db.Orders.First(o => o.Freight > 10.00M);

    需求:将数组中小于5的偶数查询出来输出到控制台

    复制代码
    //数据源
    int[] arr = { 0, 3, 2, 1, 9, 6, 8, 7, 4, 5 };

    //使用Where子句查询的查询语句
    var query = from a in arr
    where a < 5 && a % 2 == 0
    select a;

    //执行查询
    foreach (var a in query)
    {
    Console.WriteLine(a);
    }

     //两表关联

    //var list = from bdl in bodyDataList
    // join hdl in hesdDataList on bdl.ItemNo equals hdl.ItemNo into temp
    // select new ZTOutDelivery
    // {
    // DeliveryOrderNo = bdl.DeliveryOrderNo,
    // DeliveryOrderItemNo = bdl.ItemListNo,
    // ItemNo = bdl.ItemNo,
    // ItemListNo = bdl.DeliveryOrderItemNo,
    // CopGNo = bdl.CopGNo,
    // CreateDate = temp.Select(t => t.CreateDate).FirstOrDefault(),
    // CreateUserName = temp.Select(t => t.CreateName).FirstOrDefault(),
    // QTY = bdl.Qty
    // };
    //foreach (var item in bodyDataList)
    //{
    // DataTable GetByNOResult = GetByNOSearch(item.DeliveryOrderNo, item.ItemListNo);
    // if (GetByNOResult.Rows.Count > 0)
    // {

    // }
    // else {

    // }
    //}

  • 相关阅读:
    可伸缩的菜单
    Microsoft.AspNet.Identity: UserID用整型数据表示, 而不是GUID
    需要了解的技术
    微信公众号开发一些链接
    SQL Server Connection Strings for ASP.NET Web Applications https://msdn.microsoft.com/en-us/library/jj653752.aspx
    ASP.NET MVC 4 (三) 过滤器
    quick Cocos 2dx 学习网站
    获取SQL server 中的表和说明
    在 fragment 里面调用 findViewById
    gravity 和 layout_gravity
  • 原文地址:https://www.cnblogs.com/lacey/p/14683837.html
Copyright © 2011-2022 走看看