QuickAPI.Database
1.0.0
dotnet add package QuickAPI.Database --version 1.0.0
NuGet\Install-Package QuickAPI.Database -Version 1.0.0
<PackageReference Include="QuickAPI.Database" Version="1.0.0" />
<PackageVersion Include="QuickAPI.Database" Version="1.0.0" />
<PackageReference Include="QuickAPI.Database" />
paket add QuickAPI.Database --version 1.0.0
#r "nuget: QuickAPI.Database, 1.0.0"
#addin nuget:?package=QuickAPI.Database&version=1.0.0
#tool nuget:?package=QuickAPI.Database&version=1.0.0
QuickAPI.Database
Overview
QuickAPI.Database
is a foundational library for database components in QuickAPI. It provides a set of base models, a core DbContext
implementation, an interface for tenant-based multi-tenancy support, and custom data annotations for EF Core models.
This package is designed to be used in backend projects that require database operations with Entity Framework Core.
Features
- Base Models: Provides a
BaseModel
class with common fields such asId
,CreatedAt
,ModifiedAt
, andIsDeleted
. - Custom EF Core Extensions: Includes helpers for applying custom attributes and constraints on entity properties.
- Tenant Support: Implements
ITenantModel
to enforce tenant-based filtering. - Base DbContext: A
BaseContext
class that automatically applies query filters, tracks modifications, and handles tenant-aware queries. - Custom Data Annotations: Attributes for defining SQL default values, computed columns, primary keys, and constraint indexes.
Installation
To install this package via NuGet:
dotnet add package QuickAPI.Database
This package requires EF Core. Ensure you have installed Microsoft.EntityFrameworkCore
in your project.
Usage
BaseModel
All entity models should inherit from BaseModel
to get common fields and automatic tracking.
using QuickAPI.Database.DataModels;
public class Product : BaseModel
{
public decimal Price { get; set; }
}
Tenant Support
To support multi-tenancy, a model should implement ITenantModel
:
using QuickAPI.Database.DataModels;
public class Order : BaseModel, ITenantModel
{
public Guid TenantId { get; set; }
public decimal TotalAmount { get; set; }
}
BaseContext
The BaseContext
class automatically applies:
- Tenant-based filtering using
_tenantProvider
- Timestamps for created and modified fields
- Cascade delete restrictions for safer operations
Example Usage:
using Microsoft.EntityFrameworkCore;
using QuickAPI.Database.Data;
public class AppDbContext : BaseContext
{
public AppDbContext(DbContextOptions<AppDbContext> options, ITenantProvider tenantProvider)
: base(options, tenantProvider)
{
}
public DbSet<Product> Products { get; set; }
}
Applying Custom Data Annotations
Use built-in attributes for defining SQL constraints directly in your models.
Default Values
[SqlDefaultValue("getdate()")]
public DateTimeOffset CreatedAt { get; set; }
Computed Columns
[SqlComputed("Price * Quantity", stored: true)]
public decimal TotalCost { get; set; }
Primary Key Naming
[SqlPrimaryKey("PK_CustomKey", "Id")]
public class CustomEntity
{
public int Id { get; set; }
}
Notes
- This package is only for backend projects.
- It is meant to be referenced in QuickAPI but can be used in any .NET project using EF Core.
- Supports SQL Server, PostgreSQL, and other EF Core-supported databases.
License
This project is licensed under the Apache 2.0 License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.12)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.12)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|