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

 

 

转载于:https://www.cnblogs.com/luvianlan/p/4458122.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值