• C# 第六次作业


    这节课我们主要学习了.Net,LINQ和xml

    老师先为我们介绍了.Net的框架,也就是通过compiler将C# code转化成CIL(公共中间语言)再转化成CLR(公共语言运行库)。

    之后,老师为我们讲解了LINQ (Language-INtegrated Query),也就是语言集成查询,它是连接程序和数据库的桥梁,有以下特点:

    1. Programmers perform every day is finding and retrieving objects in memory, a database, or an XML file.

    2. SQL can only search relational database, not object-oriented languages.

    3. LINQ is a bridge over object-oriented languages and relational database.

    4. LINQ is SQL-like, and remove the distinctions among searching an in-memory data collection, a database, or an XML document.

    之后我尝试了自己定义并且运行一个Query▼

    其中

    IEnumerable<Customer> result = from customer in customers

                      where customer.FirstName == "Donna"

                      select customer;

    就是LINQ Query,可以看做三个部分:

    1. From clause(指定范围变量和数据源 customers)

    2. Filtering (筛选, where)

    3. Projection (映射, select)

    也是The declaration and initialization  of a query expression do not actually execute the query的例子,而

    foreach (Customer customer in result)

    {

      Console.WriteLine(customer.ToString());

    }

    则是A LINQ query is executed, or evaluated, when you iterate through the query result的例子,这两个都属于Deferred Query Evaluation。

    当然Deferred Query Evaluation也有些其他方面的内容:

    1. If the data source has changed between executions, the result will be different. It is desired in most situation.

    2. If you want to cache the result so that it can be processed later without having to reexecute the query, you can call either the ToList () or the ToArray() method to save a copy of the result.

    于是我尝试了一下ToList语句▼

    之后我们学习了 LINQ operations: join queries, grouping, aggregation, and sorting。

    其中LINQ的join子句是将一个数据源连接到另一个数据源,但是仅在满足连接条件的对象在所有的数据源中都存在时才会返回结果。

    以下是我应用join将customer和address连接到一起的程序▼

    之后我们学习了分组查询,以下是我以name为关键字的查询代码▼

  • 相关阅读:
    SQL CREATE DATABASE 语句
    SQL SELECT INTO 语句
    SQL UNION 和 UNION ALL 操作符
    复盘实战营一期毕业典礼----HHR计划----以太入门课--第一课
    抑郁研究所融资历程分享--以太一堂--直播课
    投资人分享答疑----HHR计划----以太直播课第三课
    重新理解《务实创业》---HHR计划--以太一堂第三课
    HHR计划---作业复盘-直播第三课
    电影推荐算法---HHR计划
    一堂优秀学员吕智钊分享----HHR计划----直播课第二课
  • 原文地址:https://www.cnblogs.com/luvianlan/p/4458122.html
Copyright © 2020-2023  润新知