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; + } } ///