Zonit.Extensions.Databases.Abstractions 0.0.13

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zonit.Extensions.Databases.Abstractions --version 0.0.13                
NuGet\Install-Package Zonit.Extensions.Databases.Abstractions -Version 0.0.13                
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="Zonit.Extensions.Databases.Abstractions" Version="0.0.13" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Zonit.Extensions.Databases.Abstractions --version 0.0.13                
#r "nuget: Zonit.Extensions.Databases.Abstractions, 0.0.13"                
#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 Zonit.Extensions.Databases.Abstractions as a Cake Addin
#addin nuget:?package=Zonit.Extensions.Databases.Abstractions&version=0.0.13

// Install Zonit.Extensions.Databases.Abstractions as a Cake Tool
#tool nuget:?package=Zonit.Extensions.Databases.Abstractions&version=0.0.13                

The extension facilitates CRUD creation in databases.

It speeds up the work of creating repositories, with the help of abstractions and interface handle the connection to the database.

Nuget Package Abstraction

Install-Package Zonit.Extensions.Databases.Abstractions 

NuGet Version NuGet

Nuget Package Extensions SqlServer

Install-Package Zonit.Extensions.Databases.SqlServer

NuGet Version NuGet

Example:

Model

public class Blog
{
    public Guid Id { get; set; }
    public string Title { get; set; } = string.Empty;
    public string Content { get; set; } = string.Empty;
    public DateTime Created { get; private set; } = DateTime.UtcNow;
}

internal class BlogDto(Blog x)
{
    public string Id { get; set; } = $"Id: {x.Id}";
    public string Title { get; set; } = $"Title: {x.Title}";
    public string Content { get; set; } = $"Content: {x.Content}";
    public string Created { get; set; } = $"Created: {x.Created:G}";
}

Repository

public interface IBlogRepository : IDatabaseRepository<Blog, Guid>
{ }

internal class BlogRepository(DatabaseContext _context) : DatabaseRepository<Blog, Guid>(_context), IBlogRepository
{ }

public interface IBlogsRepository : IDatabasesRepository<Blog>
{ }

internal class BlogsRepository(IDbContextFactory<DatabaseContext> _context) : DatabasesRepository<Blog, DatabaseContext>(_context), IBlogsRepository
{ }

Register

    builder.Services.AddDbSqlServer<DatabaseContext>();

    builder.Services.AddTransient<IBlogRepository, BlogRepository>();
    builder.Services.AddTransient<IBlogsRepository, BlogsRepository>();

Create

var blog = await _blogRepository.AddAsync(new Blog
{
    Title = "Hello World",
    Content = "Example content"
});

Read single

var blogSingle = await _blogRepository.GetAsync(x => x.Title == "Hello World");
var blogSingleDto = await _blogRepository.GetAsync<BlogDto>(x => x.Title == "Hello World");

Read first

var blogFirst = await _blogRepository.GetFirstAsync(x => x.Title == "Hello World");
var blogFirstDto = await _blogRepository.GetFirstAsync<BlogDto>(x => x.Title == "Hello World");

Update

var blog = await _blogRepository.GetFirstAsync(x => x.Title == "Hello World");
blog.Title = "New Title";
var update = await _blogRepository.UpdateAsync(blog);

Delete

var delete = await _blogRepository.DeleteAsync(blog.Id);

Read All

using var repository = _blogsRepository;
var blogs = await repository.GetAsync();
var blogsDto = await repository.GetAsync<BlogDto>();

API IDatabaseRepository<TEntity, TType>

Task<TEntity> AddAsync(TEntity entity);
Task<TEntity?> GetAsync(TType id);
Task<TDto?> GetAsync<TDto>(TType id);
Task<TEntity?> GetAsync(Expression<Func<TEntity, bool>> predicate);
Task<TDto?> GetAsync<TDto>(Expression<Func<TEntity, bool>> predicate);
Task<TEntity?> GetFirstAsync(Expression<Func<TEntity, bool>> predicate);
Task<TDto?> GetFirstAsync<TDto>(Expression<Func<TEntity, bool>> predicate);
Task<bool> UpdateAsync(TEntity entity);
Task<bool> DeleteAsync(TType entity);

API IDatabasesRepository<TEntity>

IDatabasesRepository<TEntity> Skip(int skip);
IDatabasesRepository<TEntity> Take(int take);
IDatabasesRepository<TEntity> Include(Expression<Func<TEntity, object>> includeExpression);
IDatabasesRepository<TEntity> Where(Expression<Func<TEntity, bool>> predicate);
IDatabasesRepository<TEntity> OrderBy(Expression<Func<TEntity, object>> keySelector);
IDatabasesRepository<TEntity> OrderByDescending(Expression<Func<TEntity, object>> keySelector);
IDatabasesRepository<TEntity> Select(Expression<Func<TEntity, TEntity>> selector);
Task<IReadOnlyCollection<TEntity>> GetAsync();
Task<IReadOnlyCollection<TDto>> GetAsync<TDto>();
Task<int> GetCountAsync();

For more information, see the Examples project.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Zonit.Extensions.Databases.Abstractions:

Package Downloads
Zonit.Extensions.Databases.SqlServer

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.5 66 1/29/2025
0.1.4 116 6/13/2024
0.1.3 121 6/5/2024
0.1.2 122 6/4/2024
0.1.1 121 6/4/2024
0.1.0 124 6/3/2024
0.0.13 129 5/1/2024
0.0.12 110 4/28/2024
0.0.11 135 4/24/2024
0.0.10 123 4/22/2024
0.0.9 127 4/21/2024
0.0.8 141 4/21/2024
0.0.7 146 4/18/2024
0.0.6 121 4/18/2024