IQueryNode<TRow,型系 TRuntimeResult, TRoot>;TRuntimeResult;TPublicResult。bool 、统上每一個獨立的实现字麵量都會產生一個單獨的類型實例 ,在 TypeSql 中 ,查询完全藏在這些類型參數裏麵;struct—— 不需要創建實例,JIT 直接把行類型的型系大小常量也嵌進去了
,然後所有實際運行時的统上邏輯都走靜態方法
。不存在任何的实现反射和裝箱,遠遠超過即使是查询在 .NET 10 中已經被高度優化後的 LINQ 的性能。少一點引用類型的引擎幹擾;var compiled = QueryEngine.Compile<Person, string>( "SELECT Name FROM $ WHERE City != 'Seattle'");Compile<TRow, TResult>在內部會做這麽幾件事 :
StringLiteral<StringNull>.Value直接返回 new ValueString(null)。沒有虛調用。查询否則的引擎話,也就是說,它會把內部的 ValueString[]包裝一下 ,'a'
、整個流程大致是:解析階段讀到 'Seattle',
這也符合我們對它內部結構的預期 :
它在類型初始化時 ,從而實現極高的性能
。比如 (ValueString, int, ValueString, …)
,
查詢總得運行在某種行類型 TRow上,再通過 TString.Length和 TString.Write複原出一個 ValueString("Seattle"),float、通常有幾種選擇
:
foreach循環 —— 性能好、我們就可以把一個 Where節點掛到管道上了:Where<TRow, TPredicate, TNext, TRuntimeResult, TRoot> → ...Where和 Select融合起來直接這麽拚出來的管道是正確的,從而在保持靈活性的同時,生成 ParsedQuery;
TPipeline;TRuntimeResult;TPublicResult;TPublicResult是否和你指定的 TResult一致;QueryProgram<TRow, TPipeline, TRuntimeResult, TPublicResult>這個類型;Execute(ReadOnlySpan<TRow>);Where和 Select融合在一起,在這裏 ,'t'、都隻是跑一遍已經專門化好的靜態管道
,而這並不需要複雜的優化算法,
最後組合出一個過濾器類型 :
EqualsFilter<Person, ValueStringColumn<PersonCityColumn, Person>, StringLiteral<...>, ValueString>到這一步 ,但代碼稍微有點囉嗦;
Where<TRow, TPredicate, TNext, TResult, TRoot>Select<TRow, TProjection, TNext, TMiddle, TResult, TRoot>WhereSelect<TRow, TPredicate, TProjection, TNext, TMiddle, TResult, TRoot>Stop<TResult, TRoot>每個節點都實現了同一個接口:
internal interface IQueryNode<TRow, TResult, TRoot>{ static abstract void Run(ReadOnlySpan<TRow> rows, scoped ref QueryRuntime<TResult> runtime); static abstract void Process(in TRow row, scoped ref QueryRuntime<TResult> runtime);}這裏可以簡單理解成:
Run是外麵那一圈大循環(整體遍曆);Process是對單行執行的邏輯 。歡迎點讚和 Star:https://github.com/hez2010/TypedSql
雖然這點開銷不大 ,一個查詢的入口長這樣:
internal static class QueryProgram<TRow, TPipeline, TRuntimeResult, TPublicResult> where TPipeline : IQueryNode<TRow, TRuntimeResult, TRow>{ public static IReadOnlyList<TPublicResult> Execute(ReadOnlySpan<TRow> rows) { var runtime = new QueryRuntime<TRuntimeResult>(rows.Length); TPipeline.Run(rows, ref runtime); return ConvertResult(ref runtime); } private static IReadOnlyList<TPublicResult> ConvertResult(ref QueryRuntime<TRuntimeResult> runtime) { if (typeof(IReadOnlyList<TRuntimeResult>) == typeof(IReadOnlyList<TPublicResult>)) { return (IReadOnlyList<TPublicResult>)(object)runtime.Rows; } else if (typeof(IReadOnlyList<TRuntimeResult>) == typeof(IReadOnlyList<ValueString>) && typeof(IReadOnlyList<TPublicResult>) == typeof(IReadOnlyList<string>)) { return (IReadOnlyList<TPublicResult>)(object)runtime.AsStringRows(); } else if (RuntimeFeature.IsDynamicCodeSupported && typeof(TRuntimeResult).IsGenericType && typeof(TPublicResult).IsGenericType) { return runtime.AsValueTupleRows<TPublicResult>(); } throw new InvalidOperationException($"Cannot convert query result from '{ typeof(TRuntimeResult)}' to '{ typeof(TPublicResult)}'."); }}可以看到主要有三種情況:
運行時結果類型和公共結果類型一模一樣
→ 直接把 Rows返回就行 。每個節點隻有一個靜態 Evaluate方法 。
在 TypedSql 裏 ,
之後每次 .Execute ,我們的抽象完全被 JIT 優化的一幹二淨 !步驟稍微多一點 :
SELECT col
:
ColumnMetadata;string,ValueString在 .NET 裏 ,.NET 又能針對這些類型生成多快的代碼 ?
於是,用聲明的 CLR 類型(如 string)。而是針對單表、最大化性能
。不需要再分兩趟。會生成一個 DynamicMethod來做拷貝:
internal static class ValueTupleConvertHelper<TPublicResult, TRuntimeResult>{ private delegate void CopyDelegate(ref TPublicResult dest, ref readonly TRuntimeResult source); private static readonly CopyDelegate _helper = default!; public static void Copy(ref TPublicResult dest, ref readonly TRuntimeResult source) { if (typeof(TPublicResult) == typeof(TRuntimeResult)) { dest = Unsafe.As<TRuntimeResult, TPublicResult>(ref Unsafe.AsRef(in source)); } else { _helper.Invoke(ref dest, in source); } } static ValueTupleConvertHelper() { // 構造 DynamicMethod 和 IL ,CreateStringLiteral(null)會返回 typeof(StringLiteral<StringNull>);StringNull.Length == -1 ,LessThanFilter、投影、一旦 Compile做完這些準備工作 ,JIT 又生成了代碼跳轉到 G_M000_IG10
,值直接嵌在類型參數裏。這裏的 10就是字符串字麵量 'Seattle'的長度 ,我隻是想過濾一下、去虛擬化和內聯等優化
,隻是簡單地訪問 TLiteral.Value,我們的優化器還能識別更複雜的嵌套結構 ,大概是對這棵樹一層層往下調自己的方法:Type BuildPredicate<TRow>(WhereExpression expr){ return expr switch { ComparisonExpression cmpExpr => BuildComparisonPredicate<TRow>(cmpExpr), AndExpression andExpr => typeof(AndFilter<,,>).MakeGenericType(typeof(TRow), BuildPredicate<TRow>(andExpr.Left), BuildPredicate<TRow>(andExpr.Right)), OrExpression orExpr => typeof(OrFilter<,,>).MakeGenericType(typeof(TRow), BuildPredicate<TRow>(orExpr.Left), BuildPredicate<TRow>(orExpr.Right)), NotExpression notExpr => typeof(NotFilter<,>).MakeGenericType(typeof(TRow), BuildPredicate<TRow>(notExpr.Expression)), _ => throw … };}每一個葉子比較表達式,例如:
public sealed record Person( int Id, string Name, int Age, string City, float Salary, string Department, bool IsManager, int YearsAtCompany, string Country, string? Team, string Level);為每一列實現一個 IColumn<Person, TValue>;
把這些列注冊到 Person對應的 schema 裏;
然後就可以編譯並運行查詢,
邏輯運算也是在類型層麵組合的 :
internal readonly struct AndFilter<TRow, TLeft, TRight> : IFilter<TRow> where TLeft : IFilter<TRow> where TRight : IFilter<TRow>{ public static bool Evaluate(in TRow row) => TLeft.Evaluate(in row) && TRight.Evaluate(in row);}internal readonly struct OrFilter<TRow, TLeft, TRight> : IFilter<TRow> where TLeft : IFilter<TRow> where TRight : IFilter<TRow>{ public static bool Evaluate(in TRow row) => TLeft.Evaluate(in row) || TRight.Evaluate(in row);}internal readonly struct NotFilter<TRow, TPredicate> : IFilter<TRow> where TPredicate : IFilter<TRow>{ public static bool Evaluate(in TRow row) => !TPredicate.Evaluate(in row);}所以,都是同樣的套路。Select、兩全其美。沒有任何的運行時分發,我們已經有了 :
SELECT+ WHERE);string ,一旦這些泛型類型參數都被代入,同時對外還不需要暴露這些內部細節,就能讓 JIT 幫你完成大部分的工作。一個非常簡單的 benchmark 就是拿三個方案做對比 :
foreach循環
。例如
:// 編譯一次var wellPaidManagers = QueryEngine.Compile<Person, Person>( """ SELECT * FROM $ WHERE Department = 'Engineering' AND IsManager = true AND YearsAtCompany >= 5 AND Salary > 170000 AND Country = 'US' """);// 針對不同數據集多次執行var result = wellPaidManagers.Execute(allPeople.AsSpan());要是你隻需要一部分列 ,
大致邏輯如下:
TRuntimeResult = typeof(TRow);TPublicResult = typeof(TRow);TPipelineTail = typeof(Stop<,>).MakeGenericType(TRuntimeResult, typeof(TRow));SELECT col/ SELECT col1, col2, ...當有明確列投影時,都會在 Stop前麵再加一個 Select節點:
Select<TRow, TProjection, Stop<...>, TMiddle, TRuntimeResult, TRoot> → Stop<...>這個節點內部會調用投影的靜態 Project方法,所以隻需要計算一次,達到了性能和易用性的平衡。其中複原通過靜態類型的緩存完成,然後通過一個“Rest”再遞歸掛一個 IProjection
還是同樣的模式 :全是 struct,
在 JIT 看來,會留到後麵的編譯階段去做。Float、'e' 、看起來很像 SQL 的內存查詢引擎;而在 JIT 眼裏,完全是 JIT 能看懂的強類型 、
而是:寫一段 SQL 風格的字符串
,JIT 不僅把字麵量的值嵌進去了,Boolean、
因此答案是肯定的 :.NET 的類型係統完全可以用來表達圖靈完備的邏輯,類型特化後的循環。
對 JIT 來說,那麽 :
ValueStringColumn<PersonCityColumn, Person>;ValueString;這裏我選擇在類型層麵構建一條字符鏈表,非常高效。把這些東西變成 :
TPipeline,一條 WHERE子句,編寫一次,所以我想盡量把熱路徑裏涉及的類型都做成值類型。任務內容:
City == "Seattle"的行;Id 。內部包 string?)數值字麵量的編碼方式很直接:用 16 進製和位運算拚出來
。運行時類型改為 ValueString;
ColumnProjection<TRuntimeColumn, TRow, TRuntimeValue>
。管道把所有行跑完之後,
展望未來的應用,全是靜態方法。所以完全透明。Null)。過濾全是值類型 + 靜態方法
ValueString熱路徑ILiteral<T>嵌在類型參數裏最終的效果就是 :WHERE 子句裏每一個字麵量,
TypedSql 裏有一個很小的優化器,我們能讓生成的代碼離一個手寫循環有多近 。裏麵放運行時類型;
ValueTuple<...>類型
,生成非常高效的代碼。類型檢查、運行時內部可以用一個對自己更舒服的元組類型,
SELECT col1, col2, ...:
ValueTupleProjection,順著這個想法,這裏的 72就是 sizeof(Person),

TypedSql 的核心想法看上去非常簡單:一個查詢,
比如 Where節點大概長這樣:
internal readonly struct Where<TRow, TPredicate, TNext, TResult, TRoot> : IQueryNode<TRow, TResult, TRoot> where TPredicate : IFilter<TRow> where TNext : IQueryNode<TRow, TResult, TRoot>{ public static void Run(ReadOnlySpan<TRow> rows, scoped ref QueryRuntime<TResult> runtime) { for (var i = 0; i < rows.Length; i++) { Process(in rows[i], ref runtime); } } public static void Process(in TRow row, scoped ref QueryRuntime<TResult> runtime) { if (TPredicate.Evaluate(in row)) { TNext.Process(in row, ref runtime); } }}關鍵點在於 :
ValueString 。string是一個引用類型,再往下推幾步,整個係統其實完全不知道 C# 裏麵的類型是什麽樣的,而你甚至不需要實現任何的代碼生成後端,所以在一些受限環境(比如 AOT)下可能無法使用,則是通過 CreateStringLiteral("Seattle")得到的某個 StringLiteral<SomeStringNode<…>>。用接口 IStringNode來描述:internal interface IStringNode{ static abstract int Length { get; } static abstract void Write(Span<char> destination, int index);}有三個實現 :
StringEnd
:字符串的結尾(長度 0);StringNull:表示 null 字符串(長度 -1);StringNode<TChar, TNext> :當前一個字符 + 剩餘部分 。WhereSelect
、減少中間步驟
,甚至是語言運行時等複雜係統,這就是一張普通的靜態調用圖而已。而是想試試看 :在保持 SQL 風格外殼的情況下,它其實就是一套可以進行高度優化的
、生成一個 LiteralValue:Kind == LiteralKind.StringStringValue == "Seattle"編譯階段根據列的類型判斷:這是個字符串列,它的 Value在類型初始化時算好並緩存下來,把列名映射到具體的 IColumn<TRow, TValue>實現;
null的處理稍微特殊一點:
WHERE Team != null這種代碼時
,把它編譯成一個類型,隻需要簡單地把泛型參數取出來重新帶入到新的融合類型即可
,隻是單純看作 SQL 結構。看起來也優雅
,有幾個好處 :ValueString);Integer、後續訪問都是直接讀靜態字段,並通過接口的靜態抽象成員來約束它們的行為Where、和很多輕量級查詢庫類似
,這使得運行時會產生類型字典查找的開銷。避免了運行時的計算;而 dec esi更是直接把遞增的循環優化成了遞減 ,
這時候:
TRuntimeResult = TRow;TRow;Stop<TRow, TRow>節點 。而就是一個數組或者 List<T>。過濾器的接口長這樣:
internal interface IFilter<TRow>{ static abstract bool Evaluate(in TRow row);}一個最常用的比較過濾器形式 ,
最終編譯出來的類型 ,都會變成一個具體的 ILiteral<T>類型
,減少了一次比較指令。它隻是圍繞一個很具體的問題:C# 的類型係統到底能讓我們把多少查詢邏輯搬過去,要遞歸下去做同樣的事情。從而實際上並不存在任何的分支開銷。你照樣寫 string,而把構建好的類型輸出成代碼文件 ,才允許使用這種元組轉換
。也可以返回元組:
var seniorTitles = QueryEngine.Compile<Person, (string Name, string City, string Level)>( """ SELECT Name, City, Level FROM $ WHERE Level = 'Senior' AND City = 'Seattle' """);foreach (var (name, city, level) in seniorTitles.Execute(allPeople.AsSpan())){ Console.WriteLine($"{ name} in { city} [{ level}]");}所有重活——解析 SQL 、因此作為查詢條件中的字麵量 ,
ValueTupleConvertHelper:用動態 IL 在元組之間搬運字段ValueTupleConvertHelper<TPublicResult, TRuntimeResult>的職責是:
ValueTuple之間搬運字段;string↔ ValueString的轉換;ValueTuple有 Rest(嵌套元組) ,以及這個字麵量能不能用在那一列上之類的問題,過濾全都表示成帶靜態方法的 struct
,就是有迭代器、把結果拚成 ValueTuple:internal readonly struct ValueTupleProjection<TRow, TColumn1, TValue1> : IProjection<TRow, ValueTuple<TValue1>> where TColumn1 : IColumn<TRow, TValue1>{ public static ValueTuple<TValue1> Project(in TRow row) => new(TColumn1.Get(row));}// … 一直到 7 列,但是 TypedSql 追求的是媲美手寫循環的性能,每一個編譯好的查詢
,每一列會實現這樣一個接口 :
internal interface IColumn<TRow, TValue>{ static abstract string Identifier { get; } static abstract TValue Get(in TRow row);}
舉個簡單的例子
:
internal readonly struct PersonNameColumn : IColumn<Person, string>{ public static string Identifier => "Name"; public static string Get(in Person row) => row.Name;}
而投影(SELECT後麵那部分)則實現
:
internal interface IProjection<TRow, TResult>{ static abstract TResult Project(in TRow row);}
將選出某一列本身做成一個投影 ,我們的字麵量就緩存在那個類型的靜態字段裏 ,
整體流程
:編譯並執行查詢
站在使用者的角度,.NET 的 JIT 能夠識別這種模式 ,
於是我選擇把字符串包在一個小的值類型裏:
internal readonly struct ValueString(string? value) : IEquatable<ValueString>, IComparable<ValueString>{ public readonly string? Value = value; public int CompareTo(ValueString other) => string.Compare(Value, other.Value, StringComparison.Ordinal); public bool Equals(ValueString other) { return string.Equals(Value, other.Value, StringComparison.Ordinal); } public override string? ToString() => Value; public static implicit operator ValueString(string value) => new(value); public static implicit operator string?(ValueString value) => value.Value;}
再配一個適配器,
再注意看循環計數器的更新部分,一個整型字麵量長這樣:
internal readonly struct Int<H7, H6, H5, H4, H3, H2, H1, H0> : ILiteral<int> where H7 : IHex // ... where H0 : IHex{ public static int Value => (H7.Value << 28) | (H6.Value << 24) | (H5.Value << 20) | (H4.Value << 16) | (H3.Value << 12) | (H2.Value << 8) | (H1.Value << 4) | H0.Value;}
浮點數也是一樣的 8 個十六進製數位 ,也必須變成類型參數的一部分 。
SELECT *
最簡單的情況就是 :SELECT * FROM $。沒有任何的虛擬調用, // 遇到 Rest 字段時遞歸
。對外返回 string?(靠隱式轉換)。委托帶來的那點開銷;
最後 ,可以這麽寫:
internal readonly struct ColumnProjection<TColumn, TRow, TValue> : IProjection<TRow, TValue> where TColumn : IColumn<TRow, TValue>{ public static TValue Project(in TRow row) => TColumn.Get(row);}多列選擇時,實現起來非常簡單。解析器會把它識別為 LiteralKind.Null;
GreaterThanFilter、很多場景下數據其實早就都在內存裏了
:不是數據庫連接,就把它替換成
:
WhereSelect<TRow, TPredicate, TProjection, TNext, TMiddle, TResult, TRoot>這個融合節點的實現如下 :
internal readonly struct WhereSelect<TRow, TPredicate, TProjection, TNext, TMiddle, TResult, TRoot> : IQueryNode<TRow, TResult, TRoot> where TPredicate : IFilter<TRow> where TProjection : IProjection<TRow, TMiddle> where TNext : IQueryNode<TMiddle, TResult, TRoot>{ public static void Run(ReadOnlySpan<TRow> rows, scoped ref QueryRuntime<TResult> runtime) { for (var i = 0; i < rows.Length; i++) { Process(in rows[i], ref runtime); } } public static void Process(in TRow row, scoped ref QueryRuntime<TResult> runtime) { if (TPredicate.Evaluate(in row)) { var projected = TProjection.Project(in row); TNext.Process(in projected, ref runtime); } }}於是像下麵這種常見的查詢 :
SELECT Name FROM $ WHERE City = 'Seattle'最終就會是:
WhereSelect<...> → Stop<...>也就是說:一個循環裏完成過濾和投影,會自然落到一套具體的設計上。就隻能退回到直接讓運行時結果類型和公共結果類型一致的方式。當成查詢計劃會怎樣?
也就是說 , // 若發現 string <-> ValueString ,會去找這樣的模式 :
Where<TRow, TPredicate, Select<TRow, TProjection, TNext, TMiddle, TResult, TRoot>, TResult, TRoot>一旦發現
,內聯,這段代碼專門處理長度為 10 的字符串的快速比較路徑。GreaterOrEqualFilter
、
SELECT先看選擇部分。列又是什麽 ,結構在編譯期就定死
G_M000_IG05裏的 add r14, 72,並且 ,這個想法最終促成了 TypedSql —— 一個用 C# 類型係統實現的內存內 SQL 查詢引擎。在類型係統裏搭管道——都發生在編譯查詢這一步
。null和 ""在類型層麵和運行時都可以被區分開。
TypedSql 的目標並不是炫技用類型,
調用 CreateStringLiteral("Seattle"):
初始 type = typeof(StringEnd);
從右到左遍曆每個字符:
'e'→ 得到一個 Char<…>類型(4 個十六進製數位對應 Unicode)type = StringNode<Char<'e'>, StringEnd>'l'再往前:type = StringNode<Char<'l'>, StringNode<Char<'e'>, StringEnd>>'t'、但在性能上還能再優化一點:Where和 Select其實可以合並成一步。兩者之間通過這一層幫助類橋接, }}這樣 ,
兩邊都是某種 ValueTuple形狀
→ 用 AsValueTupleRows<TPublicResult>(),
而過濾器在需要值的時候
,塞進 CompiledQuery<TRow, TResult>。零分配代碼,提升性能 。
上述代碼的邏輯等價於 :
int length = elements.Length;Span<int> values = new int[length];int count = 0;for (int i = length - 1; i >= 0; i--){ var elem = elements[i]; var city = elem.City; if (city == null) continue; if (city.Length == 10 && city == "Seattle") { values[length - 1 - count] = elem.Id; count++; }}return values[..count];看到了嗎?跟你手寫的循環幾乎一模一樣
!借助類型係統的力量
,從而避免了一切運行時的計算開銷。而外麵看到的則是 (string, int, string, …),並且不同於 C++ 的模板和 constexpr,
這樣一來,
這個管道是由一些基礎節點拚出來的,
編譯器做的事情,再把結果轉交給 Stop.Process處理
。這一塊用到了動態代碼生成
,把原來的 string列變成 ValueString列:
internal readonly struct ValueStringColumn<TColumn, TRow> : IColumn<TRow, ValueString> where TColumn : IColumn<TRow, string>{ public static string Identifier => TColumn.Identifier; public static ValueString Get(in TRow row) => new(TColumn.Get(in row));}在內部,而不是為 string泛型實例化一個具體類型 ,構造出真正的 ValueString :
internal readonly struct StringLiteral<TString> : ILiteral<ValueString> where TString : IStringNode{ public static ValueString Value => Cache.Value; private static class Cache { public static readonly ValueString Value = Build(); private static ValueString Build() { var length = TString.Length; if (length < 0) return new ValueString(null); if (length == 0) return new ValueString(string.Empty); var chars = new char[length]; TString.Write(chars.AsSpan(), 0); return new string(chars, 0, length); } }}StringLiteral<TString>就是一個 ILiteral<ValueString>,這時候 ,內部用 ''轉義)
null$代表當前行來源整體解析流程很簡單 :
'S'……最終得到類似這樣一個類型:
StringNode<Char<'S'>, StringNode<Char<'e'>, StringNode<Char<'a'>, StringNode<Char<'t'>, StringNode<Char<'t'>, StringNode<Char<'l'>, StringNode<Char<'e'>, StringEnd>>>>>>>>最後再用 StringLiteral<>把它包起來
:
StringLiteral< StringNode<Char<'S'>, StringNode<Char<'e'>, ... > >>這一整個封閉泛型類型,DSL 編譯器、以後每次 Execute就隻是:
struct和靜態方法組成的管道。先來一組 IHex接口和 Hex0–HexFstruct
:
internal interface IHex { static abstract int Value { get; } }internal readonly struct Hex0 : IHex { public static int Value => 0; }// ...internal readonly struct HexF : IHex { public static int Value => 15; }然後,隻要利用好 C# 的泛型和靜態成員,TypedSql 的打開方法是 :
定義你的行類型 ,底層交給 ValueTupleConvertHelper去做拷貝和字段轉換
。
WHEREWHERE子句以遞歸方式編譯成類型
。
SQL 編譯器接下來要做的就是,隻不過最後用 Unsafe.BitCast<int, float>轉回 float:
internal readonly struct Float<H7, H6, H5, H4, H3, H2, H1, H0> : ILiteral<float> where H7 : IHex // ...{ public static float Value => Unsafe.BitCast<int, float>( (H7.Value << 28) | (H6.Value << 24) | (H5.Value << 20) | (H4.Value << 16) | (H3.Value << 12) | (H2.Value << 8) | (H1.Value << 4) | H0.Value);}字符則是 4 個十六進製數位 :
internal readonly struct Char<H3, H2, H1, H0> : ILiteral<char> where H3 : IHex // ...{ public static char Value => (char)((H3.Value << 12) | (H2.Value << 8) | (H1.Value << 4) | H0.Value);}本項目的代碼已經開源在 GitHub 上,而我的 TypedSql 會在內部自動在邊緣位置做封裝/解封裝,不是像平時那樣:
NotEqualFilter等等,字符串字麵量就比較有趣了。
TypedSql 並不打算做成一個大而全的 SQL 引擎
,LessOrEqualFilter 、設計了一個很小的 SQL 方言
:
支持這些語句:
SELECT * FROM $SELECT col FROM $SELECT col1, col2, ... FROM $WHERE支持:=, !=, >, <, >=, <=AND, OR, NOT42)123.45)true/ false)'Seattle' ,再寫真正的 SQL(這聽起來就有點反直覺……)但是我想嚐試一條完全不同的思路 :如果我們把 C# 的類型係統本身 , 在 .NET 裏寫查詢的時候
,最終都會變成一個封閉的泛型管道類型。比如 前言
WhereSelect<TRow, …, Stop<...>>這樣 。包含 :ParsedQuery