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:
+3
-11
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user