| C# | SQL |
|---|---|
| > | > |
| >= | >= |
| <= | <= |
| < | < |
| == | = |
| != | <> |
// UnitPrice > 1 且 CategoryID = 2
Products._.UnitPrice > 1 && Products._.CategoryID == 2
// UnitPrice > 1 或 CategoryID = 2
Products._.UnitPrice > 1 || Products._.CategoryID == 2
WhereClip where = WhereClip.All; // 空條件,不產生 WHERE
where = where.And(Products._.UnitPrice > 1);
where = where.Or(Products._.CategoryID == 2);
WhereClip.All 代表無條件,And/Or 回傳新 WhereClip(不可變模式)。
(Products._.ProductName.Contain("apple") && Products._.UnitPrice > 1) || Products._.CategoryID == 2
對應 SQL:(ProductName LIKE '%apple%' AND UnitPrice > 1) OR CategoryID = 2
WhereClip where = WhereClip.All;
where = where.And(Products._.ProductName.Contain("apple"));
where = where.And(Products._.UnitPrice > 1);
where = where.Or(Products._.CategoryID == 2);
括號對應巢狀 And/Or 呼叫順序,建議使用運算子寫法更直觀。
WhereClip 將 SQL WHERE 子句昇華為一級物件,讓條件建構享有完整的型別安全、智慧提示、重構支援與測試能力。