linq的介绍
linq是C#中Visual Studio的扩展 用于内存操作数据库 也可以 用于对数据的整理操作。
linq的使用
linq在使用前需要引用 using System.Linq;
基本语法与SQL大同小异
from [别名] in [数据库对象.表名/对象名]
where 条件(直接写程序里面的条件语句就可以)
select [别名]
以上就是最基本的查询语句
order by 排序:
from [别名] in [数据库对象.表名/对象名]
where 条件(直接写程序里面的条件语句就可以)
orderby [别名].[属性名] asc/desc,[别名].[属性名] asc/desc
select [别名]
group by 分组:
from [别名] in [数据库对象.表名/对象名]
group [别名] by [别名].[属性名] into [别名2]
select [别名2]
注: group by into 别名后 之前的别名将失去作用
nodejs linq 使用方法:
需要引用 var Enumerable = require(‘linq’);
基础语法与C#中的linq没有太大差异
nodejs where 使用:
Enumerable.from(数据源).where(x => x.Age > 20).toArray();
上面是最标准的单个where条件查询书写方式
如果是多个where条件建议这么写:
Enumerable.from(数据源).where(
function(i){
return (i.convene_date >= query.search.start_date + ’ 00:00:00’
&& i.convene_date <= query.search.end_date + ’ 23:59:59’)
}
).toArray();
可以使用 && || 的方式继续累加条件
注意:如果要是去网上查相关知识 请注意 都是一些老的解决方案where中的条件还用“”包含 请去掉双引号 而且不要把 where 写成 Where 不要大写开头字母(有很多解决方案给的都是开头字母大写的)
nodejs order by 使用方法
降序:
Enumerable.from(数据源).orderByDescending(x => x.convene_date).toArray();
升序:
Enumerable.from(数据源).orderBy(x => x.convene_date).toArray();
注意:nodejs的linq 和 C#的linq是有差异的C#的是在orderby后面直接添加 desc/asc 而nodejs是用orderByDescending与orderBy来区分
来源:CSDN
作者:主宰者
链接:https://blog.csdn.net/qq_37516758/article/details/90517300