Linq To List 集合查詢

2022-09-23 14:18:11 字數 1854 閱讀 7040

//linq對集合的各種查詢

public static void run()

);customerlist.add(new customers() );

customerlist.add(new customers() );

customerlist.add(new customers() );

customerlist.add(new customers() );

//簡單的查詢

var customerquery = from query in customerlist

select query;

//帶where篩選

var customerwherequery = from query in customerlist

where query.id == 1 && query.name == "lus"

select query;

//排序ordering

var customerorderingquery = from query in customerlist

where query.name == "lus"

orderby query.id ascending

select query;

//分組group by

var customergroupbyquery = from query in customerlist

group query by query.name;

//可以使用into進一步查詢

var customergroupbyintoquery = from query in customerlist

group query by query.name into querygroup

where querygroup.key == "qiao"

select querygroup;

//聯接查詢 join 子句始終針對物件集合而非直接針對資料庫表執行。

list customerjoinlist = new list();

customerjoinlist.add(new customers() );

customerjoinlist.add(new customers() );

customerjoinlist.add(new customers() );

var customerjoinquery = from query1 in customerlist

join query2 in customerjoinlist

on query1.id equals query2.id

select new ;

//資料來源的型別引數始終為查詢中的範圍變數的型別。

//比如list 型別為customers 在迴圈迭代的時候型別必須可以隱式轉換為customer 有一種情況是

//這種情況下customers型別轉換為了string ..在select query.name已經將查詢目標型別定位了string型別

var customertypequery = from query in customerlist

where query.name == "lus"

select query.name;

//結合lamdba對list集合篩選(s => s.name == "qiao")

list liststring = customerlist.where(s => s.name == "qiao").tolist(); }}

public class customers

public string name

public string custom

}

mysql通過集合查詢 連線查詢與集合查詢

4.外連線查詢 在前面講述的連線操作中,返回的結果都是滿足連線條件的記錄。有些時候,開發人員或者使用者對於不滿足連線條件的部分記錄也感興趣,這個時候就需要使用外連線查詢。外連線查詢不僅可以返回滿足連線條件的記錄,對於乙個資料表中在另乙個資料表中不匹配的記錄也可以返回。外連線查詢主要包括三種 左外連線...

mysql 集合 MySql集合查詢

select語句的查詢結果是元組的集合,所以多個select語句的結果可進行集合操作。集合操作主要包括並操作union 交操作intersect 差操作except。注意,參加集合操作的各查詢結果的列數必須相同 對應的資料型別也必須相同。本示例中的資料表有student,sc,course三個,資料...

mysql遞迴查詢,查詢子集合,查詢父集合

drop function getchildlist create function getchildlist rootid varchar 100 returns longtext begin declare str longtext declare cid longtext set str se...