zoukankan      html  css  js  c++  java
  • 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为关键字的查询代码▼

  • 相关阅读:
    基础:按值传递引用类型,按引用传递引用类新 细说并沉淀
    抽象与具体
    EXTJS 零星记录 VS2008中EXTJS智能提示插件
    javascript 与 coffescript来回转换:http://js2coffee.org/
    一个冒号引发的血案
    我基本上差不多做过了coffescript所做的事
    javascript的闭包中保存的是引用与循环中事件函数处理
    用webstorm调试coffeescript
    coffeescript 下的构造函数中如何使用return语句?
    coffeescript中的forin和forof
  • 原文地址:https://www.cnblogs.com/luvianlan/p/4458122.html
Copyright © 2011-2022 走看看