EntityDbExtensions 1.2.0
dotnet add package EntityDbExtensions --version 1.2.0
NuGet\Install-Package EntityDbExtensions -Version 1.2.0
<PackageReference Include="EntityDbExtensions" Version="1.2.0" />
paket add EntityDbExtensions --version 1.2.0
#r "nuget: EntityDbExtensions, 1.2.0"
// Install EntityDbExtensions as a Cake Addin
#addin nuget:?package=EntityDbExtensions&version=1.2.0
// Install EntityDbExtensions as a Cake Tool
#tool nuget:?package=EntityDbExtensions&version=1.2.0
EntityDbExtensions
Simplify Entity Framework Delete Children Operations
Overview
Tired of manual and repetitive code when it comes to deleting child and subsequent objects with validations and nested loops? The EntityDbExtensions library simplifies the process for you. By simply invoking the method UpdateAndHandleDeletedChildren in the .Update of the root class, it will automatically handle the recursive deletion of all child, grandchild, and subsequent objects that have been removed from your root class.
The method will inspect classes containing a virtual child property with a List type, such as IEnumerable<YourClass>, ICollection<YourClass> or List<YourClass>.
public virtual IEnumerable<YourChild> YourChild { get; private set; }
It performs a validation check to determine if the object has been deleted, marking it as removed. This marking signals Entity Framework to handle the deletion seamlessly. The validation process is recursive, ensuring that all child and subsequent objects undergo thorough validation for removal.
Features
Effortless Database Operations: Streamline your Entity Framework database operations with simplified methods.
Extension Methods for DbContext: Easily perform common database operations using intuitive extension methods on your DbContexts.
Update and Handle Deleted Children: Handle the validation and removal of all deleted children from your root class with just a single command.
Getting Started
- Installation:
- Install the EntityDbExtensions NuGet package in your .NET project.
<PackageReference Include="EntityDbExtensions" Version="1.0.1" />
Usage: Add the EntityDbExtensions using statement to your code. Start using the extension methods on your Entity Framework entities.
using EntityDbExtensions;
public async Task<bool> Update(YourEntity entity)
{
var entityDb = await Get(entity.Id);
if (entityDb == null) throw new InvalidOperationException($"{nameof(YourEntity)} not found.");
_yourDbContext.UpdateAndHandleDeletedChildren(entity, entityDb); // Here the magic happens.
return await _yourDbContext.SaveChangesAsync() > 0;
}
Contribution
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.
License
This project is licensed under the MIT License.
LinkedIn - ( https://www.linkedin.com/in/alan-evandro-barboza/ )
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. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 1.2.0:
- Initial release of EntityDbExtensions.
- Simplifies recursive deletion of child and subsequent objects.
- Supports virtual child properties with generic list types.
- Seamless integration with Entity Framework and Entity Framework Core.
- Provides a more easy, efficient and automated way to handle object deletions.