5. LINQ select 敘述
IEnumerable<Product> products =
from product in model.Products
select product;
康廷數位 www.kangting.tw 5
Id Name Price
1001 商品 A 100
1002 商品 B 200
1003 商品 C 1300
… … …
… … …
n 商品 N price
6. LINQ select 敘述
IEnumerable<Product> products =
from product in model.Products
select product;
康廷數位 www.kangting.tw 6
Id Name Price
1001 商品 A 100
1002 商品 B 200
1003 商品 C 1300
… … …
… … …
n 商品 N price
select
7. LINQ select 敘述
IEnumerable<Product> products =
from product in model.Products
select product;
康廷數位 www.kangting.tw 7
Id Name Price
1001 商品 A 100
1002 商品 B 200
1003 商品 C 1300
… … …
… … …
n 商品 N price
select
select
select
select
select
8. LINQ where 敘述
IEnumerable<Product> products =
from product in model.Products
select product;
康廷數位 www.kangting.tw 8
Id Name Price
1001 商品 A 100
1002 商品 B 200
1003 商品 C 1300
… … …
… … …
n 商品 N price
9. LINQ where 敘述
IEnumerable<Product> products =
from product in model.Products
where product.Price > 1000
select product;
康廷數位 www.kangting.tw 9
Id Name Price
1001 商品 A 100
1002 商品 B 200
1003 商品 C 1300
… … …
… … …
n 商品 N price
10. LINQ orderby 敘述
IEnumerable<Product> products =
from product in model.Products
orderby product.Id
select product;
康廷數位 www.kangting.tw 10
Id Name Price
1001 商品 A 100
1002 商品 B 200
1003 商品 C 1300
… … …
… … …
n 商品 N price
11. LINQ orderby–descending 敘述
IEnumerable<Product> products =
from product in model.Products
orderby product.Id descending
select product;
康廷數位 www.kangting.tw 11
Id Name Price
n 商品 N price
… … …
… … …
1003 商品 C 1300
1002 商品 B 200
1001 商品 A 100
12. LINQ group 敘述
IEnumerable<Product> products =
from product in model.Products
select product;
康廷數位 www.kangting.tw 12
Id Name Price Category
1001 商品 A 100 CatA
1002 商品 B 200 CatA
1003 商品 C 1300 CatB
… … …
… … …
n 商品 N price CatB
13. LINQ group 敘述
IEnumerable<Product> products =
from product in model.Products
group product by product.Category ;
康廷數位 www.kangting.tw 13
Id Name Price Category
1001 商品 A 100 CatA
1002 商品 B 200 CatA
1003 商品 C 1300 CatB
… … …
… … …
n 商品 N price CatBkey:CatB
key:CatA
15. LINQ select 轉換
IEnumerable<Product> products =
from product in model.Products
select product;
康廷數位 www.kangting.tw 15
class XProduct
{
public string Id { get; set; }
public string Name { get; set; }
public int Price { get; set; }
public double SPrice { get; set; }
}
16. LINQ select 敘述
IEnumerable<Product> products =
from product in model.Products
select new XProduct()
{
Id = id,
Name = name,
Price = price,
SPrice = sPrice
};
康廷數位 www.kangting.tw 16
17. LINQ select 敘述
康廷數位 www.kangting.tw 17
Id Name Price
1001 商品 A 100
1002 商品 B 200
1003 商品 C 1300
… … …
… … …
n 商品 N price
Id Name Price SPrice
1001 商品 A 100 特價
1002 商品 B 200 特價
1003 商品 C 1300 特價
… … … …
… … … …
n 商品 N price 特價