有一個table Brand 包含三個欄位,欄位一廠牌代號(id),欄位二廠牌名稱(name),欄位三停用(isuse)。
查詢廠牌名稱含有"A"的SQL語法
select id, name, isuse from Brand where name like '%A%'
Linq 語法
db = new BaseDataDataContext();
var b = from s1 in db.Brand where s1.Name.Contains("A") select s1;
var b = from s1 in db.Brand where s1.Name.Contains("A") select s1;
查詢廠牌名稱第一個字含有"A"的SQL語法
select id, name, isuse from Brand where name like 'A%'
Linq 語法
db = new BaseDataDataContext();
var b = from s1 in db.Brand where s1.Name.StartsWith("A") select s1;
var b = from s1 in db.Brand where s1.Name.StartsWith("A") select s1;
查詢廠牌名稱最後一個字含有"A"的SQL語法
select id, name, isuse from Brand where name like '%A'
Linq 語法
db = new BaseDataDataContext();
var b = from s1 in db.Brand where s1.Name.EndsWith("A") select s1;
var b = from s1 in db.Brand where s1.Name.EndsWith("A") select s1;
查詢結果只有廠牌名稱欄位的SQL語法
select name from Brand
Linq 語法
db = new BaseDataDataContext();
var b = from s1 in db.Brand select new {name=s1.Name};
var b = from s1 in db.Brand select new {name=s1.Name};