承接上篇草圖,Richard 發現三大核心問題:
初版草圖將 DAL 上層定為 Services Interface,靈感來自「資料源可為遠端服務」。但深思後發現:服務層意味著業務邏輯、驗證、授權,這屬於 BLL 職責。若 DAL 暴露服務介面,將導致資料層膨脹、職責模糊。結論:**DAL 上層保持普通 Interface (IDataContext),服務化層上移至 BLL 之上。**
public Employee GetEmployeeById(string id);
public Employee GetEmployeeByName(string name);
public string GetEmployeePositionById(string id);
public int GetEmployeeCount();
觀察:
ctx.GetTable().InsertOnSubmit(entity) 。Fowler《企業應用架構模式》Query Object:客戶端以領域語言構建查詢,框架解釋為 SQL。
IQuery → LinqQuery/EFQuery/SqlQuery 多實現。最終確認:DAL 只是**資料存取管道**,提供統一的 Add/Update/Delete/Query(IQuery)。BLL 組裝 IQuery,DAL 解析執行。達成「以不變應萬變」。
查詢對象是打通「業務語言」與「資料庫語言」的橋樑。下篇將展示 LinqQuery 具體解析器實現與 Repository 封裝。出處:https://www.cnblogs.com/yanyangtian