FlowX.EntityFrameworkCore
1.1.0
dotnet add package FlowX.EntityFrameworkCore --version 1.1.0
NuGet\Install-Package FlowX.EntityFrameworkCore -Version 1.1.0
<PackageReference Include="FlowX.EntityFrameworkCore" Version="1.1.0" />
paket add FlowX.EntityFrameworkCore --version 1.1.0
#r "nuget: FlowX.EntityFrameworkCore, 1.1.0"
// Install FlowX.EntityFrameworkCore as a Cake Addin #addin nuget:?package=FlowX.EntityFrameworkCore&version=1.1.0 // Install FlowX.EntityFrameworkCore as a Cake Tool #tool nuget:?package=FlowX.EntityFrameworkCore&version=1.1.0
FlowX.EntityFrameworkCore
FlowX.EntityFrameworkCore is an extension package for the FlowX library, providing seamless integration with Entity Framework Core.
Features
- Simplified integration with EF Core repositories.
- Built-in support for Unit of Work patterns.
- Customizable database interaction flows.
- Enhanced error handling for EF Core operations.
- Easy-to-use fluent API for managing EF Core entities.
- Fully supports CRUD flows like CreateOne, CreateMany, GetOne, GetCollection, GetPaged, and GetCounting...
Getting Started
Prerequisites
Ensure you have the following installed:
- .NET 8.0 or higher
- Entity Framework Core
- FlowX
Installation
To install the FlowX.EntityFrameworkCore package, use the following NuGet command:
dotnet add package FlowX.EntityFrameworkCore
Or via the NuGet Package Manager:
Install-Package FlowX.EntityFrameworkCore
Usage
Usage
Below is an example of how to use FlowX.EntityFrameworkCore to handle a CreateSomeThingCommand
:
builder.Services.AddFlowX(cfg =>
{
cfg.AddModelsFromNamespaceContaining<ITestAssemblyMarker>();
cfg.AddHandlersFromNamespaceContaining<ITestAssemblyMarker>();
cfg.AddDbContextDynamic<TestDbContext>(options =>
{
options.AddDynamicRepositories();
options.AddDynamicUnitOfWork();
});
});
Examples:
public sealed class CreateSomeThingHandler(
ISqlRepository<SomeThing> sqlRepository,
IMapper mapper,
IUnitOfWork unitOfWork)
: EfCommandOneVoidHandler<SomeThing, CreateSomeThingCommand>(sqlRepository, unitOfWork)
{
protected override ICommandOneFlowBuilderVoid<SomeThing> BuildCommand(
IStartOneCommandVoid<SomeThing> fromFlow, CreateSomeThingCommand command,
CancellationToken cancellationToken)
=> fromFlow
.CreateOne(mapper.Map<SomeThing>(command))
.WithCondition(_ => None.Value)
.WithErrorIfSaveChange(SomeErrorDetail());
}
public class UpdateSomeThingHandler(
ISqlRepository<SomeThing> sqlRepository,
IUnitOfWork unitOfWork,
IMapper mapper)
: EfCommandOneVoidHandler<SomeThing, UpdateSomeThingCommand>(sqlRepository)
{
protected override ICommandOneFlowBuilderVoid<SomeThing> BuildCommand(
IStartOneCommandVoid<SomeThing> fromFlow, UpdateSomeThingCommand command,
CancellationToken cancellationToken)
=> fromFlow
.UpdateOne(x => x.Id == command.Id)
.WithSpecialAction(null)
.WithCondition(_ => None.Value)
.WithModify(SomeThing => Mapper.Map(command, SomeThing))
.WithErrorIfNull(MasterDataErrorDetail.SomeThingError.NotFound())
.WithErrorIfSaveChange(SomeErrorDetail());
}
public sealed class GetSomeThingHandler(ISqlRepository<SomeThing> sqlRepository, IMapper mapper)
: EfQueryOneHandler<SomeThing, GetSomeThingQuery, SomeThingResponse>(sqlRepository)
{
protected override IQueryOneFlowBuilder<SomeThing, SomeThingResponse> BuildQueryFlow(
IQueryOneFilter<SomeThing, SomeThingResponse> fromFlow, GetSomeThingQuery query)
=> fromFlow
.WithFilter(x => x.Id == query.Id)
.WithSpecialAction(x => x.ProjectTo<SomeThingResponse>(Mapper.ConfigurationProvider))
.WithErrorIfNull(SomeErrorDetail());
}
// ... Other Flows
Key Concepts
EF Core Repositories
FlowX.EntityFrameworkCore provides repository abstractions that simplify CRUD operations with EF Core. You can
inject ISqlRepository<T>
to access database entities directly.
Unit of Work
Unit of Work ensures that all database operations within a command are executed in a single transaction, providing consistency and reliability.
Error Handling
This extension includes advanced error handling tailored for EF Core, enabling you to catch and manage database-related errors gracefully.
Contributing
We welcome contributions to FlowX.EntityFrameworkCore! To contribute, please:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a detailed explanation of your changes.
License
FlowX.EntityFrameworkCore is licensed under the MIT License. See LICENSE
for more details.
Contact
For inquiries, reach out to [your email or GitHub link].
Extend your FlowX capabilities with FlowX.EntityFrameworkCore!
Package Name | Description | .NET Version | Document |
---|---|---|---|
FlowX | FlowX core | 8.0, 9.0 | ReadMe |
FlowX.EntityFrameworkCore | This is the FlowX extension package using EntityFramework to fetch data | 8.0, 9.0 | This Document |
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 is compatible. 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. |
-
net8.0
- FlowX (>= 1.1.0)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
-
net9.0
- FlowX (>= 1.1.0)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.