Hydrogen.Repo 2.7.0-preview.2

This is a prerelease version of Hydrogen.Repo.
dotnet add package Hydrogen.Repo --version 2.7.0-preview.2
                    
NuGet\Install-Package Hydrogen.Repo -Version 2.7.0-preview.2
                    
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="Hydrogen.Repo" Version="2.7.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hydrogen.Repo" Version="2.7.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="Hydrogen.Repo" />
                    
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 Hydrogen.Repo --version 2.7.0-preview.2
                    
#r "nuget: Hydrogen.Repo, 2.7.0-preview.2"
                    
#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 Hydrogen.Repo@2.7.0-preview.2
                    
#: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=Hydrogen.Repo&version=2.7.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Hydrogen.Repo&version=2.7.0-preview.2&prerelease
                    
Install as a Cake Tool

Hydrogen Repo

This package uses SqlKata as query builder, if you have doubts check its documentation.

Installation

dotnet add package Hydrogen.Repo
dotnet add package Hydrogen.Repo.Abstractions

Models

Create a model

[DeletedAt] //The deletion will be soft and not logical.
[Table("Users")] // Table name in the database.
public class User
{
    [PrimaryKey] // Mark the property as the primary key.
    [AutoGenerateGuid] // Indicate that it will be an auto-generated GUID field.
    public Guid Id { get; set; }    
    public Guid RoleId { get; set; }
    public string Email { get; set; } = string.Empty;
    public string Password { get; set; } = string.Empty;
    public bool TwoFactor { get; set; }
    [CreatedAt] // Indicate that the property functions as a timestamp of when the element was created.
    public DateTime CreatedAt { get; set; }
    [UpdatedAt] // Indicate that the property functions as a timestamp of when the element was updated.
    public DateTime UpdatedAt { get; set; }
    
}

Database context

Create a database context interface

public interface IDatabaseContext : IHydrogenContext
{

}

Create a class that implements the database context interface

public class DatabaseContext : HydrogenContext, IDatabaseContext
{
    public DatabaseContext(IDbConnection connection, DbConnectionType connectionType, bool debug = false, Action<SqlResult>? action = null) 
            : base(connection, connectionType, debug, action)
        {
        }
}

Unit of work (optional)

Create an interface for the unit of work

public interface IDatabaseUnitOfWork : IHydrogenUnitOfWork
{
}

Create a class that implements the unit of work interface

class DatabaseUnitOfWork : HydrogenUnitOfWork, IDatabaseUnitOfWork
{
    public DatabaseUnitOfWork(IDatabaseContext DatabaseContext) : base(DatabaseContext)
    {
    }
}

Repositories

Create the repository interface

public interface IUserRepository : IHydrogenRepository<User, Guid>
{
    // Add your functions
}

Create a class that implements the repository interface

The repository already implements the basic functions.

public class UserRepository : HydrogenRepository<User, Guid>, IUserRepository
{
    public UserRepository(IDatabaseContext databaseContext) : base(databaseContext)
    {
    }
}

Add the implementations to the service collection

var connectionBuilder = new SqliteConnectionStringBuilder()
{
    DataSource = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "test.db"),
};

        
var connection = new SqliteConnection(connectionBuilder.ConnectionString);

collection.AddScoped<IDatabaseContext>(_ => new DatabaseContext(connection, DbConnectionType.SQLite, true));
collection.AddScoped<IDatabaseUnitOfWork, DatabaseUnitOfWork>();
collection.AddScoped<IUserRepository, UserRepository>();

Use it in a service

private readonly IUserRepository _userRepository;

public OptionService(IUserRepository userRepository)
{
    _userRepository = userRepository;
}

public async Task<IEnumerable<UserDto>> GetAllAsync(CancellationToken ct)
{
    return _userRepository.GetAsync<UserDto>(ct);
}

Available functions

  • Any
  • Count
  • Insert
  • Bulk insert
  • Bulk update
  • Update
  • Delete
  • Get
  • Pagination
  • First
  • First or default
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.7.0-preview.2 27 9/16/2025
2.7.0-preview.1 30 9/16/2025
2.6.0 205 8/24/2025
2.6.0-preview.1 18 9/15/2025
2.4.0 207 8/7/2025
2.0.2 155 6/16/2025
2.0.1 170 6/14/2025
2.0.0 299 6/13/2025
1.8.2 284 6/10/2025
1.8.1 485 6/10/2025
1.6.2 140 12/20/2024
1.6.0 169 9/16/2024