Skip to content

karenpayneoregon/ef-core-soft-delete

Repository files navigation

Entity Framework Core 3x/5 soft deletables

This repository contains code to show how to use HasQueryFilter to provide soft deletes against any model which implements a specific Interface.

Microsoft TechNet article

screenshot

Setup

  • Run the following script to create the database and populate tables.
  • From Visual Studio solution explorer select Restore Nuget packages.
  • Ensure WindowsFrontEnd or WindowsFrontEndCore5 is the startup project.
  • Build the solution
  • Run

EntityLibrary Requires

  • Microsoft Framework 4.7.2 or higher
  • Microsoft Visual 2017 or higher
  • Microsoft SQL-Server 2012 or higher

EntityLibraryCore5 Requires

  • Microsoft Framework .NET Core 5, C# 9
  • Microsoft Visual 2019 or higher
  • Microsoft SQL-Server 2012 or higher

private void RemoveCurrentSupplierButton_Click(object sender, EventArgs e)
{

    var currentSupplier = _supplierBindingSource.Current as Suppliers;

    if (!Question($"Remove {currentSupplier.CompanyName}")) return;

    using (var context = new NorthwindContext())
    {
        context.Entry(currentSupplier).State = EntityState.Deleted;
        context.SaveChanges();
        _supplierBindingSource.RemoveCurrent();
    }
}

About

Examples for HasQueryFilter with EF Core 3 and EF Core 5

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages