Zonit.Extensions.Databases.Abstractions
0.0.13
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
<PackageReference Include="Zonit.Extensions.Databases.Abstractions" Version="0.0.13" />
<PackageVersion Include="Zonit.Extensions.Databases.Abstractions" Version="0.0.13" />
<PackageReference Include="Zonit.Extensions.Databases.Abstractions" />
paket add Zonit.Extensions.Databases.Abstractions --version 0.0.13
#r "nuget: Zonit.Extensions.Databases.Abstractions, 0.0.13"
#addin nuget:?package=Zonit.Extensions.Databases.Abstractions&version=0.0.13
#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 Package Extensions SqlServer
Install-Package Zonit.Extensions.Databases.SqlServer
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 | Versions 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. 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. |
-
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
A powerful and flexible library for building repository layers and managing database CRUD operations. Features clean abstractions, dynamic query capabilities, DTO support, and easy extensions for integrating external or computed data from any source—database, API, or service. Designed to let you focus on business logic, not plumbing. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.12 | 248 | 5 days ago |
1.0.11 | 274 | 5 days ago |
1.0.10 | 271 | 5 days ago |
1.0.9 | 138 | 18 days ago |
1.0.8 | 134 | 20 days ago |
1.0.7 | 138 | 20 days ago |
1.0.6 | 67 | 23 days ago |
1.0.5 | 132 | a month ago |
1.0.4 | 143 | a month ago |
1.0.3 | 109 | 2 months ago |
1.0.2 | 152 | 2 months ago |
1.0.1 | 169 | 2 months ago |
1.0.0 | 88 | 2 months ago |
0.1.14 | 90 | 2 months ago |
0.1.13 | 91 | 2 months ago |
0.1.12 | 206 | 2 months ago |
0.1.11 | 198 | 2 months ago |
0.1.10 | 188 | 2 months ago |
0.1.9 | 186 | 2 months ago |
0.1.8 | 193 | 2 months ago |
0.1.7 | 193 | 2 months ago |
0.1.6 | 202 | 2 months ago |
0.1.5 | 117 | 5 months ago |
0.1.4 | 143 | 6/13/2024 |
0.1.3 | 131 | 6/5/2024 |
0.1.2 | 129 | 6/4/2024 |
0.1.1 | 128 | 6/4/2024 |
0.1.0 | 132 | 6/3/2024 |
0.0.13 | 139 | 5/1/2024 |
0.0.12 | 117 | 4/28/2024 |
0.0.11 | 143 | 4/24/2024 |
0.0.10 | 132 | 4/22/2024 |
0.0.9 | 133 | 4/21/2024 |
0.0.8 | 148 | 4/21/2024 |
0.0.7 | 154 | 4/18/2024 |
0.0.6 | 127 | 4/18/2024 |