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为关键字的查询代码▼

  • 相关阅读:
    Dllimport函数時无法在Dll中找到的入口点
    cb35a_c++_STL_算法_for_each
    cb34a_c++_STL_算法_查找算法_(7)_lower_bound
    cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
    cb32a_c++_STL_算法_查找算法_(5)adjacent_find
    cb31a_c++_STL_算法_查找算法_(4)find_first_of
    cb30a_c++_STL_算法_查找算法_(3)search_find_end
    cb29a_c++_STL_算法_查找算法_(2)search_n
    cb28a_c++_STL_算法_查找算法_(1)find_find_if
    cb27a_c++_STL_算法_最小值和最大值
  • 原文地址:https://www.cnblogs.com/luvianlan/p/4458122.html
Copyright © 2011-2022 走看看