select用法:

1、Dictionary<string, string>转json

Newtonsoft.Json.JsonConvert.SerializeObject(dicSubject.Select(l => new { label=l.Key,value=l.Value}))

2、Select可以修改数组、集合中的值

arrSub.Select(l => subjects.First(m => m.Name.Equals(l)).Id);

3.  可以对查询出来的结果做一些转换,下面的例子在数组中查找以"B"开头的名字,然后全部转成小写输出:

 string[] names = { "Jack", "Bob", "Bill", "Catty", "Willam" };

 var rs = from n in names
where n.StartsWith("B")
select n.ToLower();
foreach (var r in rs)
Console.WriteLine(r);

4. 返回匿名类型,比如Linq To Sql查询数据库的时候只返回需要的信息,下面的例子是在Northwind数据库中查询Customer表,返回所有名字以"B"开头的客户的ID和名称:

 NorthwindDataContext dc = new NorthwindDataContext();
var cs = from c in dc.Customers
where c.ContactName.StartsWith("B")
select new
{
CustomerID = c.CustomerID,
CustomerName = c.ContactTitle + " " + c.ContactName
};
foreach (var c in cs)
Console.WriteLine(c);

5. 对于数组,select可以对数组元素以及索引进行操作:

  string[] names = { "Jack", "Bob", "Bill", "Catty", "Willam" };
var rs = names.Select((name, index) => new { Name = name, Index = index });
foreach (var r in rs)
Console.WriteLine(r);

6. 组合查询,可以对多个数据源进行组合条件查询(相当于使用SelectMany函数),下面的例子其实就相对于一个双重循环遍历:

   int[] numbersA = { , , , , , ,  };
int[] numbersB = { , , , , }; var pairs =
from a in numbersA
from b in numbersB
where a < b
select new {a, b}; Console.WriteLine("Pairs where a < b:");
foreach (var pair in pairs)
Console.WriteLine("{0} is less than {1}", pair.a, pair.b);

7.用Linq To Sql的话,相当于进行一次子查询:

  NorthwindDataContext dc = new NorthwindDataContext();
var rs = from c in dc.Customers
from o in c.Orders
where o.ShipCity.StartsWith("B")
select new { CustomerName = c.ContactName, OrderID = o.OrderID }; foreach (var r in rs)
Console.WriteLine(r);

Ling之select的更多相关文章

  1. 最全的ORACLE-SQL笔记

    -- 首先,以超级管理员的身份登录oracle sqlplus sys/bjsxt as sysdba --然后,解除对scott用户的锁 alter user scott account unloc ...

  2. Matplotlib数据可视化(6):饼图与箱线图

    In [1]: from matplotlib import pyplot as plt import numpy as np import matplotlib as mpl mpl.rcParam ...

  3. 【C#】解析C#中LING的使用

    LING提供了一种从数据源中获取数据的方式,不同的语言已经形成了很多种关联的数据源.LING(Language Integrated Query,语言集成查询)提供一种通用的从不同的数据源中获取数据的 ...

  4. SELECT INTO 和 INSERT INTO SELECT 两种表复制语句

    Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) values(value1,value2,...)这种形式的在应用程序开发中必不可少.但我 ...

  5. select、poll、epoll之间的区别总结

    select.poll.epoll之间的区别总结 05/05. 2014 select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪 ...

  6. LINQ to SQL Select查询

    1. 查询所有字段 using (NorthwindEntities context = new NorthwindEntities()) { var order = from n in contex ...

  7. ADO.NET一小记-select top 参数问题

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 最近使用ADO.NET的时候,发现select top @count xxxx 不 ...

  8. iosselect:一个js picker项目,在H5中实现IOS的select下拉框效果

    具体文档和demo可以访问github:https://github.com/zhoushengmufc/iosselect 移动端浏览器对于select的展示样式是不一致的,ios下是类似原生的pi ...

  9. SQL Server中SELECT会真的阻塞SELECT吗?

    在SQL Server中,我们知道一个SELECT语句执行过程中只会申请一些意向共享锁(IS) 与共享锁(S), 例如我使用SQL Profile跟踪会话86执行SELECT * FROM dbo.T ...

随机推荐

  1. hosts是什么意思?Hosts文件有什么作用和功能?

    hosts是什么意思?Hosts文件有什么作用和功能? 熟悉网络的朋友们都会用到hosts文件,针对还不清楚hosts是什么意思以及hosts文件有什么功能和作用?针对此问题,本文就为大家进行解答   ...

  2. luoguP4735 最大异或和

    https://www.luogu.org/problemnew/show/P4735 令 s 数组为 a 数组的异或前缀,则题目要求的式子可变为 s[p - 1] ^ s[n] ^ x,s[n] ^ ...

  3. Python之路Python内置函数、zip()、max()、min()

    Python之路Python内置函数.zip().max().min() 一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算, ...

  4. selenium+PhantomJS简单爬虫

    #!/usr/bin/env python # -*- coding: utf-8 -*- ''' Created on 2017年10月19日 @author: zzy ''' import tim ...

  5. vue is detected

    Vue.js is detected on this page. Devtools inspection is not available because it's in production mod ...

  6. Tomcat 连接数与线程池详解

    前言 在使用tomcat时,经常会遇到连接数.线程数之类的配置问题,要真正理解这些概念,必须先了解Tomcat的连接器(Connector). 在前面的文章 详解Tomcat配置文件server.xm ...

  7. Kibana6.x.x源码分析--ngReact使用

    ngReact  GitHub地址:https://github.com/ngReact/ngReact

  8. BZOJ 2935/ Poi 1999 原始生物

    [bzoj2935][Poi1999]原始生物   2935: [Poi1999]原始生物 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 145  So ...

  9. 数独求解问题(DFS+位运算优化)

    In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgrids. For exa ...

  10. Tensorlflow-解决非线性回归问题

    import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt #使用numpy生成200个随机点,范围从-0.5到0 ...