Aiursoft.DbTools 9.0.11

dotnet add package Aiursoft.DbTools --version 9.0.11                
NuGet\Install-Package Aiursoft.DbTools -Version 9.0.11                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aiursoft.DbTools" Version="9.0.11" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Aiursoft.DbTools --version 9.0.11                
#r "nuget: Aiursoft.DbTools, 9.0.11"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Aiursoft.DbTools as a Cake Addin
#addin nuget:?package=Aiursoft.DbTools&version=9.0.11

// Install Aiursoft.DbTools as a Cake Tool
#tool nuget:?package=Aiursoft.DbTools&version=9.0.11                

DBTools

MIT licensed Pipeline stat Test Coverage NuGet version (Aiursoft.CSTools) ManHours

DbTools are Aiursoft's common database tools. It simplifies the process of registering DbContext and updating database. So your application can easily switch from different database types.

Installation

To install Aiursoft.DbTools to your project from nuget.org:

dotnet add package Aiursoft.DbTools

Project structure

---
title: Project dependency diagram
---

stateDiagram-v2
    Aiursoft.DbTools.InMemory --> Aiursoft.DbTools
    Aiursoft.DbTools.Sqlite --> Aiursoft.DbTools
    Aiursoft.DbTools.MySql --> Aiursoft.DbTools
    Aiursoft.DbTools.Switchable --> Aiursoft.DbTools
    Demo.Entities --> Aiursoft.DbTools
    Demo.Sqlite --> Aiursoft.DbTools.Sqlite
    Demo.Sqlite --> Demo.Entities
    Demo.MySql --> Aiursoft.DbTools.MySql
    Demo.MySql --> Demo.Entities
    Demo.InMemory --> Aiursoft.DbTools.InMemory
    Demo.InMemory --> Demo.Entities
    Demo.WebApp --> Aiursoft.DbTools.Switchable
    Demo.WebApp --> Demo.InMemory
    Demo.WebApp --> Demo.MySql
    Demo.WebApp --> Demo.Sqlite
    Aiursoft.DbTools.SqlServer --> Aiursoft.DbTools

Usage

In your startup.cs:

public void ConfigureServices(IConfiguration configuration, IWebHostEnvironment environment, IServiceCollection services)
{
    var (connectionString, dbType, allowCache) = configuration.GetDbSettings();
    services.AddSwitchableRelationalDatabase(
        dbType: EntryExtends.IsInUnitTests() ? "InMemory": dbType,
        connectionString: connectionString,
        supportedDbs:
        [
            new MySqlSupportedDb(allowCache: allowCache, splitQuery: false),
            new SqliteSupportedDb(allowCache: allowCache, splitQuery: true),
            new InMemorySupportedDb()
        ]);

    services
        .AddControllersWithViews()
        .AddApplicationPart(typeof(Startup).Assembly);
}

In your appsettings.json:

{
    "ConnectionStrings": {
        "AllowCache": "True",
        "DbType": "Sqlite",
        "DefaultConnection": "DataSource=app.db;Cache=Shared"
    }
}

Or:

{
  // sudo docker run -d --name db -e MYSQL_RANDOM_ROOT_PASSWORD=true -e MYSQL_DATABASE=kahla -e MYSQL_USER=kahla -e MYSQL_PASSWORD=kahla_password -p 3306:3306 hub.aiursoft.cn/mysql
  "ConnectionStrings": {
    "AllowCache": "True",
    "DbType": "MySql",
    "DefaultConnection": "Server=localhost;Database=kahla;Uid=kahla;Pwd=kahla_password;"
  }
}

Or:

{
  "ConnectionStrings": {
    "AllowCache": "False",
    "DbType": "InMemory"
  }
}

Simple, isn't it?

Your database project need to be different with your web project, you need the following command to generate migrations:

cd ./Demo.MySql
dotnet ef migrations add Init --context "MySqlContext" -s ../Demo.WebApp/Demo.WebApp.csproj
cd ..

cd ./Demo.Sqlite
dotnet ef migrations add Init --context "SqliteContext" -s ../Demo.WebApp/Demo.WebApp.csproj
cd ..

For more usage, please check the Demo app in the demos folder!

How to contribute

There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.

Even if you with push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.

We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Aiursoft.DbTools:

Package Downloads
Aiursoft.DbTools.SqlServer

A tool for database.

Aiursoft.DbTools.InMemory

A tool for database.

Aiursoft.DbTools.Sqlite

A tool for database.

Aiursoft.DbTools.MySql

A tool for database.

Aiursoft.DbTools.Switchable

Nuget package of 'Switchable' provided by Aiursoft

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.11 42 2/27/2025
9.0.4 130 2/23/2025
9.0.3 134 2/12/2025
9.0.2 152 2/1/2025
9.0.1 133 1/16/2025
9.0.0 177 12/30/2024
8.0.12 334 11/13/2024
8.0.11 384 10/9/2024
8.0.10 333 8/18/2024
8.0.9 306 7/10/2024
8.0.8 164 7/7/2024
8.0.7 161 6/29/2024
8.0.6 166 6/5/2024
8.0.5 217 5/16/2024
8.0.4 184 5/4/2024
8.0.3 330 3/17/2024
8.0.2 191 3/17/2024
8.0.1 283 2/25/2024
8.0.0 720 2/19/2024
7.0.19 344 2/14/2024
7.0.18 312 2/4/2024
7.0.17 308 2/2/2024
7.0.16 331 2/2/2024
7.0.15 320 1/30/2024
7.0.14 521 1/10/2024
7.0.13 424 1/4/2024
7.0.12 1,213 12/30/2023
7.0.11 430 12/24/2023
7.0.10 605 12/1/2023
7.0.9 638 11/26/2023
7.0.8 699 11/18/2023
7.0.7 545 11/12/2023
7.0.6 600 11/2/2023
7.0.5 493 11/2/2023
7.0.4 612 10/31/2023
7.0.3 508 10/27/2023
7.0.2 677 10/11/2023
7.0.1 799 9/13/2023
7.0.0 752 9/5/2023
6.0.32 652 8/4/2023
6.0.31 694 8/3/2023
6.0.30 672 7/11/2023
6.0.29 915 6/30/2023
6.0.28 734 6/29/2023
6.0.27 596 6/29/2023
6.0.26 656 6/29/2023
6.0.25 572 6/29/2023
6.0.24 679 6/28/2023
6.0.23 672 6/28/2023
6.0.22 875 6/18/2023
6.0.21 840 6/14/2023
6.0.20 815 6/5/2023
6.0.19 859 5/27/2023
6.0.18 804 5/27/2023
6.0.17 835 5/27/2023
6.0.16 788 5/27/2023
6.0.15 793 5/27/2023
6.0.14 819 5/27/2023
6.0.13 823 5/19/2023
6.0.12 834 5/19/2023
6.0.11 826 5/19/2023
6.0.10 831 5/19/2023
6.0.9 781 5/19/2023
6.0.8 823 5/11/2023
6.0.7 2,852 8/4/2022
6.0.6 1,423 7/6/2022
6.0.5 1,720 5/13/2022
6.0.0 1,515 3/27/2022
5.0.9 1,488 5/31/2021
5.0.8 1,358 5/23/2021
5.0.7 1,373 5/7/2021
5.0.6 1,403 4/14/2021
5.0.5 1,495 2/16/2021
5.0.4 1,472 1/29/2021
5.0.3 1,459 1/27/2021
5.0.2 1,554 12/9/2020
5.0.1 1,458 11/30/2020
5.0.0 1,371 11/14/2020
3.2.11 1,654 10/18/2020
3.2.10 1,542 10/3/2020
3.2.9 1,514 10/2/2020
3.2.8 1,590 9/10/2020
3.2.7 1,573 9/2/2020
3.2.6 1,603 8/12/2020
3.2.5 1,633 7/31/2020
3.2.4 1,663 7/3/2020
3.2.3 1,564 6/25/2020
3.2.2 1,592 6/18/2020
3.2.1 1,561 6/5/2020
3.2.0 1,665 6/4/2020
3.1.14 1,759 6/4/2020
3.1.13 1,777 5/25/2020
3.1.12 1,660 5/20/2020
3.1.11 1,638 5/18/2020
3.1.10 1,674 5/18/2020
3.1.9 1,643 5/17/2020
3.1.8 1,666 5/12/2020
3.1.7 1,711 5/2/2020
3.1.6 1,736 5/1/2020
3.1.5 1,734 4/21/2020
3.1.4 1,464 4/19/2020