DALQueryChain 1.1.0.4-preview

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

// Install DALQueryChain as a Cake Tool
#tool nuget:?package=DALQueryChain&version=1.1.0.4-preview&prerelease                

DALQueryChain

NuGet Version and Downloads count License

DALQueryChain позволяет упростить работу с DAL уровнем, предоставляя гибкую систему составления запроса, закрытым от прямого доступа к ORM и IQueryable.

Начало работы:

Установка основного пакета из NuGet:

  • Install-Package DALQueryChain

Дополнительные пакеты:

Для Linq2Db ORM:

  • Install-Package DALQueryChain.Linq2Db

Для EntityFramework ORM:

  • Install-Package DALQueryChain.EntityFramework

Конфигурация проекта:

В Startup/Program прописать регистрацию DALQueryChain

public class Startup
{
    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        //...
        services.AddQueryChain(Assembly.GetAssembly("DALAssemblyName"));
        //...
    }
}

Использование библиотеки:

Забираем из DI:

IDALQueryChain<TestContext> queryChain

Или создаем экземпляр:

using var queryChain = new BuildQuery<TestContext>(_context, _serviceProvider);

Примеры использования:

Get:

var maxUserId = queryChain.For<User>().Get.Select(x => x.Id).Max(); //Получение максимального Id
var activeUsers = await queryChain.For<User>().Get.Where(x => x.IsActive).ToListAsync(); //Получение активных записей
var workspaces = queryChain.For<Workspace>().Get.LoadWith(x => x.Permissions).ThenLoad(x => x.Users); //Получение записей с зависимостями

Insert:

var user = new User
    {
        AccessFailedCount = 1,
        CreateAt = DateTime.Now,
        DeleteAt = DateTime.Now,
        Email = Guid.NewGuid().ToString(),
        EmailConfirmed = false,
        ModifyAt = DateTime.Now,
        PasswordHash = "",
        PhoneConfirmed = false,
        RoleId = 1,
        Salt = "",
        IsActive = true,
        Username = Guid.NewGuid().ToString()
    };

var user = await queryChain.For<User>().Insert.InsertWithObjectAsync(user); // Вставка записи в таблицу с ее возвратом

Delete:

await queryChain.For<User>().Delete.DeleteAsync(x => true); //Удаление всех записей в таблице

await _qs.For<User>().Delete.BulkSoftDeleteAsync(users); //Мягкое удаление (необходимо переопределение в репозитории)

Update:

queryChain.For<User>().Update.BulkUpdate(object); //Массовое обновление записей

_qs.For<User>().Update
    .Where(x => true)
    .Set(x => x.Email, () => Guid.NewGuid().ToString())
    .Update(); //Обновление указанных полей в записях

Репозитории и триггеры:

UserRepository:

public class UserRepository : BaseRepository<TestContext, User>
{
    private readonly ITestDI _testDI;

    public UserRepository(TestContext context, ITestDI testDI) : base(context)
    {
        _testDI = testDI;
    }

    protected override async Task OnBeforeDelete(CancellationToken ctn = default)
    {
        var deletedEntities = await GetTriggerData(ctn);

        //Some Actions...
    }

    protected override async Task OnAfterDelete(CancellationToken ctn = default)
    {
        var deletedEntities = await GetTriggerData(ctn);

        //Some Actions...
    }

    protected override async Task OnBeforeUpdate(CancellationToken ctn = default)
    {
        var updatedEntities = await GetTriggerData(ctn);

        //Some Actions...
    }

    protected override async Task OnAfterUpdate(CancellationToken ctn = default)
    {
        var updatedEntities = await GetTriggerData(ctn);

        //Some Actions...
    }

    protected override async Task OnBeforeInsert(CancellationToken ctn = default)
    {
        var insertedEntities = await GetTriggerData(ctn);

        //Some Actions...
    }

    protected override async Task OnAfterInsert(CancellationToken ctn = default)
    {
        var insertedEntities = await GetTriggerData(ctn);

        //Some Actions...
    }

    protected override Task SoftBulkDelete(IEnumerable<User> model, CancellationToken ctn = default)
    {
        //Some Actions...
    }

    protected override Task SoftDelete(Expression<Func<User, bool>> predicate, CancellationToken ctn = default)
    {
        //Some Actions...
    }

    protected override Task SoftBulkDelete(Expression<Func<User, bool>> predicate, CancellationToken ctn = default)
    {
        //Some Actions...
    }

    protected override Task SoftDelete(User model, CancellationToken ctn = default)
    {
        //Some Actions...
    }

    public void Method()
    {
        _testDI.Test();
    }
}

Использование:

var repository = queryChain.Repository<UserRepository>();
repository.Method();
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on DALQueryChain:

Package Downloads
DALQueryChain.Linq2Db

Query Chain for Data Access Layer built on the Linq2Db ORM, allowing you to proxy queries to the DAL and use triggers

DALQueryChain.EntityFramework

Query Chain for Data Access Layer built on the Entity Framework ORM, allowing you to proxy queries to the DAL and use triggers

DALQueryChain.Filter

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.7.1 215 5/21/2024
1.1.7 130 5/21/2024
1.1.6 486 2/9/2024
1.1.5 153 2/9/2024
1.1.4 155 2/6/2024
1.1.3 689 9/12/2023
1.1.2 209 9/12/2023
1.1.1 321 9/6/2023
1.1.0.9-preview 215 8/25/2023
1.1.0.8-preview 323 8/7/2023
1.1.0.7-preview 543 8/3/2023
1.1.0.6-preview 249 7/12/2023
1.1.0.5-preview 458 5/25/2023
1.1.0.4-preview 171 5/25/2023
1.1.0.3-preview 200 5/18/2023
1.1.0.2-preview 209 5/2/2023
1.1.0.1-preview 196 5/2/2023
1.0.19 1,160 11/24/2022
1.0.18 678 10/4/2022
1.0.17 618 9/30/2022
1.0.16 616 9/30/2022
1.0.15 646 9/28/2022
1.0.14 651 9/28/2022
1.0.13 647 9/27/2022
1.0.12 659 9/26/2022
1.0.11 670 9/23/2022
1.0.10 635 9/16/2022
1.0.9 685 9/8/2022
1.0.8 548 8/22/2022
1.0.7 564 8/17/2022
1.0.6 537 8/17/2022
1.0.5 528 8/15/2022
1.0.4 547 8/13/2022
1.0.3 592 8/13/2022 1.0.3 is deprecated because it has critical bugs.
1.0.2 549 8/11/2022
1.0.1 533 8/4/2022
1.0.0 536 8/4/2022