DALQueryChain.EntityFramework
1.1.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DALQueryChain.EntityFramework --version 1.1.3
NuGet\Install-Package DALQueryChain.EntityFramework -Version 1.1.3
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.EntityFramework" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DALQueryChain.EntityFramework --version 1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DALQueryChain.EntityFramework, 1.1.3"
#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.EntityFramework as a Cake Addin
#addin nuget:?package=DALQueryChain.EntityFramework&version=1.1.3
// Install DALQueryChain.EntityFramework as a Cake Tool
#tool nuget:?package=DALQueryChain.EntityFramework&version=1.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DALQueryChain
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 | Versions 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.
-
net7.0
- DALQueryChain (>= 1.1.3)
- Microsoft.EntityFrameworkCore (>= 7.0.5)
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 |
---|---|---|
1.1.7.1 | 66 | 5/21/2024 |
1.1.7 | 77 | 5/21/2024 |
1.1.6 | 104 | 2/9/2024 |
1.1.5 | 74 | 2/9/2024 |
1.1.4 | 87 | 2/6/2024 |
1.1.3 | 103 | 9/12/2023 |
1.1.2.1-preview | 87 | 9/12/2023 |
1.1.2 | 106 | 9/12/2023 |
1.1.1 | 122 | 9/6/2023 |
1.1.0.9-preview | 95 | 8/25/2023 |
1.1.0.8-preview | 89 | 8/7/2023 |
1.1.0.7-preview | 88 | 8/3/2023 |
1.1.0.6-preview | 68 | 7/12/2023 |
1.1.0.5-preview | 97 | 5/25/2023 |
1.1.0.4-preview | 73 | 5/25/2023 |
1.1.0.3-preview | 84 | 5/18/2023 |
1.1.0.2-preview | 88 | 5/2/2023 |
1.1.0.1-preview | 87 | 5/2/2023 |
1.0.19 | 354 | 11/24/2022 |
1.0.18 | 357 | 10/4/2022 |
1.0.17 | 356 | 9/30/2022 |
1.0.16 | 350 | 9/30/2022 |
1.0.15 | 369 | 9/28/2022 |
1.0.14 | 392 | 9/28/2022 |
1.0.13 | 367 | 9/27/2022 |
1.0.12 | 384 | 9/26/2022 |
1.0.11 | 411 | 9/23/2022 |
1.0.10 | 382 | 9/16/2022 |
1.0.9 | 382 | 9/8/2022 |