DbLocator 2.0.0

dotnet add package DbLocator --version 2.0.0
                    
NuGet\Install-Package DbLocator -Version 2.0.0
                    
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="DbLocator" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbLocator" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DbLocator" />
                    
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 DbLocator --version 2.0.0
                    
#r "nuget: DbLocator, 2.0.0"
                    
#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.
#:package DbLocator@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DbLocator&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DbLocator&version=2.0.0
                    
Install as a Cake Tool

DbLocator

DbLocator is a .NET library that simplifies database interactions for multi-database tenant applications on SQL Server.

📊 Architecture

graph TD
    %% Groups
    subgraph DbLocator

        subgraph Tenants
            T1[Acme Corp]
            T2[Beta Corp]
            T3[Gamma Corp]
        end

        subgraph Database Types
            DT1[Client]
            DT2[Reporting]
        end

        subgraph Database Servers
            S1[Database Server 1]
            S2[Database Server 2]
        end

        subgraph Databases
            D1[Acme_Client]
            D2[Acme_Reporting]
            D3[Beta_Client]
            D4[Beta_Reporting]
            D5[Gamma_Client]
            D6[Gamma_Reporting]
        end

    end

    T1 --> DT1
    T1 --> DT2
    T2 --> DT1
    T2 --> DT2
    T3 --> DT1
    T3 --> DT2

    DT1 --> D1
    DT2 --> D2
    DT1 --> D3
    DT2 --> D4
    DT1 --> D5
    DT2 --> D6

    %% Database to Server mapping
    D1 --> S1
    D2 --> S1
    D3 --> S1
    D4 --> S1
    D5 --> S2
    D6 --> S2

📚 Documentation

Full documentation is available at https://chizer1.github.io/DbLocator

🚀 Quick Start

Installation

The package is available on NuGet:

dotnet add package DbLocator

Basic usage

Setup

var dbLocator = new Locator("{yourConnectionString}");

var tenantCode = "Acme";
var tenantId = await dbLocator.CreateTenant(
    tenantName: "Acme Corp",
    tenantCode: tenantCode,
    tenantStatus: Status.Active
);

var databaseTypeName = "Client";
var databaseTypeId = await dbLocator.CreateDatabaseType(databaseTypeName: databaseTypeName);

var databaseServerId = await dbLocator.CreateDatabaseServer(
    databaseServerName: "Database Server",
    databaseServerHostName: "localhost",
    databaseServerIpAddress: null,
    databaseServerFullyQualifiedDomainName: null,
    isLinkedServer: false
);

var databaseId = await dbLocator.CreateDatabase(
    databaseName: $"{tenantCode}_{databaseTypeName}",
    databaseServerId: databaseServerId,
    databaseTypeId: databaseTypeId,
    affectDatabase: true,
    useTrustedConnection: true
);

await dbLocator.CreateConnection(
    tenantId: tenantId,
    databaseTypeId: databaseTypeId
);

Run script in database

CREATE TABLE User (
    Id INT PRIMARY KEY IDENTITY,
    Name NVARCHAR(100) NOT NULL
);

INSERT INTO User (Name) VALUES ('Alice'), ('Bob'), ('Charlie');

Connect and query

using var connection = await dbLocator.GetConnection(
    tenantId: tenantId,
    databaseTypeId: databaseTypeId
);

using var command = connection.CreateCommand();
command.CommandText = "SELECT * FROM Users";

using var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync())
    Console.WriteLine($"User: {reader["Name"]}");

📖 Examples

🤝 Contributing

I welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please read Contributing Guidelines for more details.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.0 67 7/19/2025