EntityDbExtensions 1.0.1

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

// Install EntityDbExtensions as a Cake Tool
#tool nuget:?package=EntityDbExtensions&version=1.0.1

EntityDbExtensions

Simplify Entity Framework Delete Child Operations

Overview

Tired of manual and repetitive code when it comes to deleting child and subsequent objects with validations and nested loops? This library simplifies the process for you. By simply invoking a method 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 generic list type, such as IEnumerable<YourClass> or ICollection<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 examination and 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.

Getting Started

  1. Installation:
    • Install the EntityDbExtensions NuGet package in your .NET project.
dotnet add package EntityDbExtensions


Usage:
Add the necessary 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);

    _yourDbContext.HandleDeletedChildren(entity, entityDb);  // Here the magic happens.

    _yourDbContext.Set<YourEntity>().Update(entity);
    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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 Downloads Last updated
1.2.0 85 2/15/2024
1.0.1 81 2/13/2024
1.0.0 71 2/13/2024

Version 1.0.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 efficient and automated way to handle object deletions.