using Microsoft.EntityFrameworkCore;
namespace MyWebLog.Data;
public static class PageExtensions
{
///
/// Count the number of pages
///
/// The number of pages
public static async Task CountAll(this DbSet db) =>
await db.CountAsync().ConfigureAwait(false);
///
/// Retrieve a page by its ID (non-tracked)
///
/// The ID of the page to retrieve
/// The requested page (or null if it is not found)
public static async Task FindById(this DbSet db, string id) =>
await db.SingleOrDefaultAsync(p => p.Id == id).ConfigureAwait(false);
///
/// Retrieve a page by its permalink (non-tracked)
///
/// The permalink
/// The requested page (or null if it is not found)
public static async Task FindByPermalink(this DbSet db, string permalink) =>
await db.SingleOrDefaultAsync(p => p.Permalink == permalink).ConfigureAwait(false);
}