Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Orbis25/FoundationKit/llms.txt
Use this file to discover all available pages before exploring further.
IBaseRepository<TModel> is the core interface that establishes the full data-access contract for any entity-based repository in FoundationKit. By programming against this interface rather than a concrete class, your application code stays decoupled from EF Core specifics — swap out the backing store, apply decorators, or mock the interface in unit tests without touching business logic. Every method returns an awaitable Task (or an IQueryable for composable queries), and all async methods accept a CancellationToken so callers can respect request cancellation gracefully.
The single generic parameter TModel must derive from BaseModel, which provides the standard audit fields (Id, CreatedAt, UpdatedAt, CreatedBy, UpdatedBy, IsDeleted) that the repository methods rely on internally.
Generic Constraint
TModel must inherit FoundationKit.Domain.Models.BaseModel. This ensures every entity exposes the Id (Guid), IsDeleted, CreatedAt, and CreatedBy properties that several methods depend on for audit-field preservation and soft-delete logic.
Methods
GetPaginatedListAsync
Returns a single page of results wrapped in aPaginationResult<TModel>, including total record count, total pages, and the actual page items.
Pagination settings. Contains
Page (1-based page number), Qyt (items per page), OrderByDesc (sort direction), NoPaginate (bypass pagination and return all results), and Query (optional free-text search token your code can use in the expression).Optional LINQ predicate to filter the dataset before pagination is applied. Passed directly to a
Where clause on the underlying IQueryable.Property selector used to order results. When
null, ordering falls back to CreatedAt descending (or ascending based on paginate.OrderByDesc).Propagates cancellation from the calling HTTP request or background job.
Zero or more navigation-property selectors applied as EF Core
Include calls, enabling eager loading without additional queries.Returns a
PaginationResult<TModel> with ActualPage, Qyt, PageTotal, Total, and Results. When NoPaginate is true, only Results is populated (all matching rows) and pagination metadata fields are zero.GetListAsync
Returns the full unpaginated list of matching entities as a materialisedIEnumerable<TModel>.
When
true (default) results are ordered descending; when false, ascending.Optional filter predicate. Pass
null to retrieve all records.Optional ordering selector. Falls back to
CreatedAt when null.Propagates cancellation.
Navigation-property selectors for eager loading.
A fully materialised, in-memory collection of entities. Use
GetAll if you need a composable IQueryable instead.GetAll
Returns a composableIQueryable<TModel> that has not yet hit the database. Use this when you need to chain additional LINQ operators before execution.
Optional
Where predicate.Sort direction. Default ordering property is
CreatedAt.Optional sort-property selector.
Navigation properties for eager loading via EF Core
Include.A deferred query. Call
.ToListAsync(), .FirstOrDefaultAsync(), or further .Where() / .Select() before awaiting.CreateAsync
Adds a new entity to the database inside a transaction and returns the persisted entity (with any database-generated values such as default timestamps populated).The fully initialised entity instance to insert. Set all required properties before passing it in;
BaseModel audit fields (CreatedAt, CreatedBy) are expected to be set by the caller or EF value generators.Propagates cancellation.
The same entity instance, now tracked and reflecting any database-assigned values.
UpdateAsync
Updates an existing entity. Two overloads are available: one that exposes theverifyEntity flag, and a convenience overload that omits it (equivalent to calling the full overload with verifyEntity: false). When verifyEntity is true (the default on the full overload), the repository first fetches the current entity from the database to preserve the original CreatedBy and CreatedAt audit fields before applying the update.
The entity with updated property values. Must have a valid
Id matching an existing row.Propagates cancellation.
When
true, the repository looks up the existing record first and copies CreatedBy / CreatedAt from it before calling Update. Set to false to skip the pre-fetch if you are certain the audit fields are already correct on the supplied model. The two-parameter convenience overload always behaves as if verifyEntity is false.The updated entity, or
null if verifyEntity was true and no record with the given Id was found.UpdatePartialEntityAsync
Attaches an entity to the EF Core change tracker and marks only the specified properties asModified, so that only those columns are included in the generated UPDATE statement.
An entity instance (does not need to be tracked). Must have its
Id set to target the correct row.A list of property selectors identifying exactly which columns to update. Properties not listed are excluded from the SQL
UPDATE.Propagates cancellation.
Completes when
SaveChangesAsync has finished. Does not wrap the save in a full CommitAsync transaction — call CommitAndResultAsync separately if you need transaction semantics.GetByIdAsync
Fetches a single entity by its primary key (Guid), with optional eager loading and change-tracking control.
The primary key (
BaseModel.Id) of the entity to retrieve.When
true, the entity is returned without being added to the EF Core change tracker. Suitable for read-only scenarios where you do not intend to update the entity.Propagates cancellation.
Navigation properties for eager loading.
The matched entity, or
null when no record with the given Id exists.SoftRemoveAsync
Performs a logical (soft) delete by settingIsDeleted = true on the entity and persisting the change. The row remains in the database and can be restored.
Primary key of the entity to soft-delete.
Propagates cancellation.
true when the record was found and updated successfully; false when no entity with the given Id exists.RemoveAsync
Permanently deletes an entity from the database. This operation cannot be undone.Primary key of the entity to delete.
Propagates cancellation.
true if the record was found and removed; false if no matching record was found.ExistAsync
Checks whether at least one entity matching the optional predicate exists in the database.Optional filter. When
null, returns true if the table contains any rows at all.Propagates cancellation.
true if at least one matching row exists; otherwise false.GetOneAsync
Returns the first entity matching the given predicate, ornull when no match is found. Maps directly to EF Core’s FirstOrDefaultAsync.
Filter predicate. Unlike
ExistAsync, this parameter is required.Propagates cancellation.
The first matching entity, or
null.CountAsync
Returns the number of entities that satisfy all supplied predicates. Multiple expressions are ANDed together by successiveWhere calls.
Propagates cancellation.
Zero or more filter predicates. Passing no expressions counts all rows in the table.
The row count satisfying all predicates.
CommitAndResultAsync
Saves all pending change-tracker mutations inside a database transaction. Returnsnull on success or an error message string on failure, instead of throwing — useful when you want to control error handling in the calling layer rather than catching exceptions.
Propagates cancellation.
null when the transaction committed successfully. The base exception message string when an error occurred (transaction is rolled back automatically).Usage Example
ImplementIBaseRepository<TModel> by extending BaseRepository<TContext, TModel>, which provides the complete EF Core-backed implementation out of the box.