sql 、linq、Lambda 查询语句的格式

LINQ的书写格式如下:
from 临时变量 in 集合对象
where 条件表达式
[order by条件]   
select 临时变量中被查询的值  
[group by 条件]

Lambda表达式的书写格式如下:
集合对象.Where(临时变量=>(条件表达式))
Sql、Linq、Lambda 查询语句示例

1.查询Student表的所有记录

Sql:
    select * from student
Linq:
    from s in Students
    select s
Lambda:    
    Students.Select( s => true) 

2.查询Student表中的所有记录的Sname、Ssex和Class列。

Sql:
     select sname,ssex,class from student
Linq:
     from s in Students
     select new {
        s.SNAME,
        s.SSEX,
        s.CLASS}
Lambda:
    Students.Select( s => new {SNAME = s.SNAME,SSEX = s.SSEX,CLASS = s.CLASS})

3.查询教师所有的单位即不重复的Depart列。

Sql:
    select distinct depart from teacher
Linq:
    from t in Teachers.Distinct()
    select t.DEPART
Lambda:
    Teachers.Distinct().Select( t => t.DEPART)

4.查询Score表中成绩在60到80之间的所有记录。

Sql:
    select * from score where degree between 60 and 80
Linq:
    from s in Scores
    where s.DEGREE >= 60 && s.DEGREE < 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值