Add DbBase.Find<T> static generic finder (yak: Console app for Before (ActiveRecord-style) > ○ Add DbBase.Find<T> static generic)

This commit is contained in:
2026-09-14 20:45:12 +01:00
parent 92b9e3f784
commit c21c6416cf
2 changed files with 33 additions and 11 deletions
+3 -11
View File
@@ -31,19 +31,11 @@ public class Client : DbBase
///
/// This mirrors how an ActiveRecord-style ORM might surface a static
/// finder on the domain class itself — it rides the <c>DbContext</c> leak
/// from the entity's back-reference.
/// from the entity's back-reference. Delegates to
/// <see cref="DbBase.Find{T}"/> for the common traversal logic.
/// </summary>
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;
}
=> DbBase.Find<Client>(c => c.Name == name, db);
}
/// <summary>