LINQ

資料來源: 一個結合where、group、orderby的linq(http://yangxinde.pixnet.net/blog/post/31357272-%E4%B8%80%E5%80%8B%E7%B5%90%E5%90%88where%E3%80%81group%E3%80%81orderby%E7%9A%84linq)

保哥線上講堂:LINQ 快速上手(https://www.slideshare.net/WillHuangTW/linq-46081487)

ASP.NET MVC-LINQ 之 insert update select(https://dotblogs.com.tw/newmonkey48/2013/09/16/118726)

List<Object> arr= new List<Object>();

using (DataBaseDataContext db = new DataBaseDataContext())
{
    //where  like 
    arrR = (from o in db.table
            where o.field.Contains("text")
    //group
    /*where o.field== "text"
    group o.field1 new Obj (){
            Attribute1 = o.field1,
            Attribute2 = o.field2,
            Attribute3 = o.field3
    } into g
    //orderby g.Key.field1
    select g.Key).ToList();*/
    select o).ToList();
}

Select

第一種方法如上

第二種方法

想要串接多個條件

Insert

Update

select出來之後,直接對值做修改,再儲存起來。

Delete

Join

在Join時,on的比較只能用 [equals] 不能用 [==]

題外話

LINQ 不只能查詢SQL,還可以查詢清單、陣列 等等。

WHERE

假如我們想要取得清單中的某個物件,可利用下列方式。

order by

.OrderByDescending(o=>o.SN)

取幾筆

.Take(count)

整數清單 轉 字串清單

Last updated

Was this helpful?