From 92b9e3f78459338b2426fd0a9dd5b0ada2f254d3 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Mon, 14 Sep 2026 20:43:47 +0100 Subject: [PATCH] Console app for Before (ActiveRecord-style) > Add Client.FindByName convenience wrapper --- src/Before/Client.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Before/Client.cs b/src/Before/Client.cs index 48c9e90..7beb365 100644 --- a/src/Before/Client.cs +++ b/src/Before/Client.cs @@ -23,6 +23,27 @@ public class Client : DbBase { Orders = new ClientOrders(this); } + + /// + /// Convenience lookup: walks the 's tracked entities, + /// finds the first whose + /// equals . Returns null when no match. + /// + /// This mirrors how an ActiveRecord-style ORM might surface a static + /// finder on the domain class itself — it rides the DbContext leak + /// from the entity's back-reference. + /// + public static Client? FindByName(string name, DbContext? db) + { + if (db is null) + return null; + + foreach (var e in db.Tracked) + if (e is Client c && c.Name == name) + return c; + + return null; + } } ///