Aiursoft.DbTools 9.0.12

dotnet add package Aiursoft.DbTools --version 9.0.12
                    
NuGet\Install-Package Aiursoft.DbTools -Version 9.0.12
                    
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.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aiursoft.DbTools" Version="9.0.12" />
                    
Directory.Packages.props
<PackageReference Include="Aiursoft.DbTools" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aiursoft.DbTools --version 9.0.12
                    
#r "nuget: Aiursoft.DbTools, 9.0.12"
                    
#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.
#addin nuget:?package=Aiursoft.DbTools&version=9.0.12
                    
Install Aiursoft.DbTools as a Cake Addin
#tool nuget:?package=Aiursoft.DbTools&version=9.0.12
                    
Install Aiursoft.DbTools as a Cake Tool

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 (7)

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 (1)

Showing the top 1 popular GitHub repositories that depend on Aiursoft.DbTools:

Repository Stars
AiursoftWeb/Kahla
Kahla is a cross-platform business messaging app. Mirror of https://gitlab.aiursoft.cn/aiursoft/kahla
Version Downloads Last updated
9.0.12 218 20 days ago
9.0.11 215 a month ago
9.0.4 158 a month ago
9.0.3 140 2 months ago
9.0.2 155 2 months ago
9.0.1 135 3 months ago
9.0.0 178 3 months ago
8.0.12 343 5 months ago
8.0.11 385 6 months ago
8.0.10 333 7 months ago
8.0.9 308 9 months ago
8.0.8 164 9 months ago
8.0.7 163 9 months ago
8.0.6 166 10 months ago
8.0.5 218 5/16/2024
8.0.4 186 5/4/2024
8.0.3 330 3/17/2024
8.0.2 193 3/17/2024
8.0.1 286 2/25/2024
8.0.0 770 2/19/2024
7.0.19 363 2/14/2024
7.0.18 314 2/4/2024
7.0.17 310 2/2/2024
7.0.16 332 2/2/2024
7.0.15 321 1/30/2024
7.0.14 523 1/10/2024
7.0.13 428 1/4/2024
7.0.12 1,247 12/30/2023
7.0.11 432 12/24/2023
7.0.10 607 12/1/2023
7.0.9 640 11/26/2023
7.0.8 701 11/18/2023
7.0.7 546 11/12/2023
7.0.6 601 11/2/2023
7.0.5 495 11/2/2023
7.0.4 614 10/31/2023
7.0.3 510 10/27/2023
7.0.2 678 10/11/2023
7.0.1 800 9/13/2023
7.0.0 754 9/5/2023
6.0.32 652 8/4/2023
6.0.31 695 8/3/2023
6.0.30 673 7/11/2023
6.0.29 915 6/30/2023
6.0.28 734 6/29/2023
6.0.27 598 6/29/2023
6.0.26 659 6/29/2023
6.0.25 572 6/29/2023
6.0.24 683 6/28/2023
6.0.23 673 6/28/2023
6.0.22 877 6/18/2023
6.0.21 843 6/14/2023
6.0.20 817 6/5/2023
6.0.19 861 5/27/2023
6.0.18 806 5/27/2023
6.0.17 839 5/27/2023
6.0.16 791 5/27/2023
6.0.15 794 5/27/2023
6.0.14 822 5/27/2023
6.0.13 824 5/19/2023
6.0.12 840 5/19/2023
6.0.11 829 5/19/2023
6.0.10 835 5/19/2023
6.0.9 782 5/19/2023
6.0.8 824 5/11/2023
6.0.7 2,858 8/4/2022
6.0.6 1,428 7/6/2022
6.0.5 1,729 5/13/2022
6.0.0 1,523 3/27/2022
5.0.9 1,496 5/31/2021
5.0.8 1,369 5/23/2021
5.0.7 1,383 5/7/2021
5.0.6 1,412 4/14/2021
5.0.5 1,510 2/16/2021
5.0.4 1,484 1/29/2021
5.0.3 1,470 1/27/2021
5.0.2 1,565 12/9/2020
5.0.1 1,474 11/30/2020
5.0.0 1,382 11/14/2020
3.2.11 1,665 10/18/2020
3.2.10 1,553 10/3/2020
3.2.9 1,526 10/2/2020
3.2.8 1,600 9/10/2020
3.2.7 1,584 9/2/2020
3.2.6 1,613 8/12/2020
3.2.5 1,645 7/31/2020
3.2.4 1,674 7/3/2020
3.2.3 1,575 6/25/2020
3.2.2 1,604 6/18/2020
3.2.1 1,573 6/5/2020
3.2.0 1,676 6/4/2020
3.1.14 1,769 6/4/2020
3.1.13 1,788 5/25/2020
3.1.12 1,671 5/20/2020
3.1.11 1,648 5/18/2020
3.1.10 1,687 5/18/2020
3.1.9 1,654 5/17/2020
3.1.8 1,677 5/12/2020
3.1.7 1,723 5/2/2020
3.1.6 1,748 5/1/2020
3.1.5 1,746 4/21/2020
3.1.4 1,477 4/19/2020