博客
关于我
c#的LINQ
阅读量:610 次
发布时间:2019-03-13

本文共 543 字,大约阅读时间需要 1 分钟。

LINQ代表语言集成查询(Language Integrated Query)

LINQ是.NET框架的扩展,它允许我们以使用SQL查询数据库的方式来查询数据集合。
使用LINQ,你可以从数据库、对象集合以及XML文档中查询数据
2.语法
(1)from <迭代变量(新定义)> in <数据集合> where <条件> [orderby <元素的一部分] [select <整个元素或者元素的一部分>]
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

(2)方法中使用Lambda表达式

在这里插入图片描述
上述语句等同于:
在这里插入图片描述
在这里插入图片描述

注意:(1)不写select语句表示返回的是数组/集合的元素。

(2)LINQ可以对多种存储数据的对象进行操作,如Objects,Dataset,SQL,Entities,XML。
在这里插入图片描述
当对类的对象进行操作时,即对于Linq to Objects, 返回数据类型是IEnumerable,T取决于select子句的结果。
一般使用推断类型var表示,编译器会自己判断类型
在这里插入图片描述
(3)当where语句中的条件有多个时(用&&连接),可以分开写。
在这里插入图片描述
3.结果数据转换
将IEnumerable类型的数据转换为List、Array、Dictionary
在这里插入图片描述
4.结果数据计算
对IEnumerable类型的数据进行计数、求和、求平均、取第一个数据
在这里插入图片描述

转载地址:http://osuaz.baihongyu.com/

你可能感兴趣的文章
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>