Linq to SQL 雖最終僅支援 SQL Server,但其架構設計充分體現了可擴展性。核心在於 IProvider 介面與 ProviderAttribute 的結合,透過橋接模式將「抽象」與「實現」解耦。
在強型別 DataContext 上標註 [Provider(typeof(SqlProvider))] 即可指定提供者。若未指定,AttributeMetaModel 建構子會預設使用 SqlProvider:
ProviderAttribute[] attrs = (ProviderAttribute[])this.contextType
.GetCustomAttributes(typeof(ProviderAttribute), true);
if (attrs != null && attrs.Length == 1)
this.providerType = attrs[0].Type;
else
this.providerType = typeof(SqlProvider);
DataContext.Init() 中會根據 MetaModel.ProviderType 動態建立 IProvider 實例並呼叫 Initialize:
if (model.ProviderType == null)
throw Error.ProviderTypeNull();
Type providerType = model.ProviderType;
if (!typeof(IProvider).IsAssignableFrom(providerType))
throw Error.ProviderDoesNotImplementRequiredInterface(providerType, typeof(IProvider));
this.provider = (IProvider)Activator.CreateInstance(providerType);
this.provider.Initialize(this.services, connection);
若單純用繼承擴充資料庫類型與版本,類別階層將爆炸性增長。微軟採用橋接模式:
IProvider (如 SqlProvider, OracleProvider)IDataService (如 SqlDataService, OracleDataService)IProvider.Initialize(IDataService, connection) 將兩者組合,避免子類別間重複程式碼,也符合「組合優於繼承」原則。

實務專案中常見「資料庫類型」與「版本差異」雙重變化,橋接模式能有效隔離變化點。Linq to SQL 雖未實作多資料庫,但架構已預留擴充空間,展現優良架構「應付明天變化」的能力。