.forgejo/workflows | ||
Alveus.DAL.Common | ||
Alveus.DAL.PostgreSql | ||
Alveus.DAL.Tests | ||
.gitignore | ||
Alveus.DataAccessLayer.sln | ||
Alveus.ruleset | ||
LICENSE.md | ||
README.md |
Alveus Data Access Layer (DAL)
A data access layer framework for applying a repository design pattern.
Currently only implements PostgreSQL.
Installation
Install the package via NuGet feed https://nuget.alveus.dev
Defining Entities
Entities are C# classes that represent database tables. Use attributes to define the mapping:
[Table("users")]
public class User
{
[PrimaryKey("id")]
public int Id { get; set; }
[Column("username")]
public string Username { get; set; }
[Column("email")]
public string Email { get; set; }
}
Repository Pattern
The DAL implements the repository pattern through IRepository<TEntity>
. Each entity type has its
own repository that inherits from this interface:
BaseRepository<TEntity>
provides methods to be used by the inheriting repositories.
public class UserRepository : PgsqlRepository<User>, IUserRepository
{
// Implementation of repository methods
}
Transaction Support
When registering DbProvider as a scoped service, the TransactionProvider can be used to wrap db operations in transactions. Nested transactions are supported with postgres.
Database Migrator
A migration helper is provided which will create a migrations
table and apply the series of sql scripts present in the migrations directory.
These scripts are sorted by filename in ascending order and will only be applied if they haven't already.