Linq 基礎查詢

2022-08-30 14:21:23 字數 1945 閱讀 5339

//

基本查詢

var query = from c in

workflows

select

c;//

帶條件查詢

var query = from c in

workflows

where c.pid == 1

select

c;//

查詢顯示不同的列

from c in

workflows

select

new//

排序from c in

workflows

orderby

c.id descending

selectc//

去除某個欄位的重複

from c in

workflows

where c.pid == 1

select

c.step).distinct()

//帶條件的分組查詢

from c in

workflows

where c.pid == 1

group c by c.step into g

select

gfrom c in

cities

where c.state == "

北京市"

selectc//

分組後查詢最大的 min或最小的

from c in

cities

group c by c.state into g

select

new//

查詢包含陣列中的資料

from c in

cities

where (new

string ).contains(c.state)

select

cfrom c in

cities

orderby

c.id descending,c.sz_code ascending

selectc//

查詢content欄位包含「西」的和字段state以「河」開頭的資料 並連線

(from c in

cities

where c.content.contains("西"

)select

c).union

(from c in

cities

where c.state.startswith("河"

) select

c)//

子查詢from p in

persontables

select

new//

左連線查詢

from p in

persontables

join c

incities on p.cityid equals c.id

into pro

from x in

pro.defaultifempty()

//顯示左邊沒有關聯的資料,如果不用defaultifempty() 則不會顯示左邊表的全部資料

from x in

proselect

new//

多表關聯join查詢

from c in

cities

join p

inpersontables on c.id equals p.cityid

into cro

from x in

cro.defaultifempty()

join w

inworkflows on x.id equals w.id

into xrw

from s in

xrw.defaultifempty()

select

new

Linq 基礎查詢

linq查詢語句編寫工具可以用linqpad,挺好用的 一下是我自己學習linq to sql的查詢語句 基本查詢 from c in workflows select c 帶條件查詢 from c in workflows where c.pid 1 select c 查詢顯示不同的列 from ...

Linq查詢基礎

1.language integrate query,linq將查詢表示式作為c 的一種語法,查詢表示式訪問的資料來源是包含一組資料的集合物件,ienumerable或iqueryable型別 返回的查詢結果也是包含一組資料的集合物件,由於linq中查詢的表示式是訪問的是物件,該物件可以表示各種型別...

LINQ 之 基本 LINQ 查詢操作

在 linq 查詢中,第一步是指定資料來源。像在大多數程式語言中一樣,必須先宣告變數,才能使用它。在 linq 查詢中,最先使用from子句的目的是引入資料來源和範圍變數。queryallcustomers 是 ienumerable型別 資料來源 customers 和範圍變數 cust var ...