為避免硬編碼字符串如 ClassA.MemberA.MemberB,設計了一組擴展類,支持通過 Lambda 表達式構建 MongoDB 查詢,自動解析成員路徑。
m => m.MemberA.MemberB → "MemberA.MemberB")。QueryCollection 對象,支持鏈式調用。 x.PoppedSegments)
.Matches(p => p.AssignedNetwork.Name, bsonRegex);
// 3. 繼承轉換:基類 STPaymentTransaction -> 子類 STPaymentCompanyCredit
QueryEx<MDDelivery>.CollectionAs<STPaymentTransaction, STPaymentCompanyCredit>(x => x.Payments)
.Matches(p => p.Company.Name, bsonRegex);
// 4. 雙層集合 + 繼承
QueryEx<MDDelivery>.Collection(x => x.Parcels)
.CollectionMemberAs<STCustomPropertyRuntime, STNumericPropertyRuntime>(p => p.CustomProps)
.Matches(p => p.Value, bsonRegex);
優勢