Biwen.EFCore.SoftDelete 1.0.0

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

// Install Biwen.EFCore.SoftDelete as a Cake Tool
#tool nuget:?package=Biwen.EFCore.SoftDelete&version=1.0.0                

Biwen.EFCore.SoftDelete

GitHub license PRs Welcome

  • 实现DbContext的软删除功能

NuGet 包

  • dotnet add package Biwen.EFCore.SoftDelete --version 1.0.0

开发环境

运行环境

Easy to Use

Step 1 Model定义


[PrimaryKey("Id")]
public class Blog : ISoftDeleted
{
    //...
    public int Id { get; set; }
    public string Title { get; set; } = null!;
    public string Content { get; set; } = null!;
    public int AuthorId { get; set; }

    //请注意这里的IsDeleted默认必须是false!表示未删除
    public bool IsDeleted { get; set; } = false;
}

Step 2 继承SoftDeleteDbContext


public class TestDbContext : SoftDeleteDbContext
{
	public TestDbContext(DbContextOptions<TestDbContext> options)
		: base(options)
	{
	}
    //...
	public DbSet<Blog> Blogs { get; set; }

	protected override void OnModelCreating(ModelBuilder builder)
	{
		base.OnModelCreating(builder);
		//根据情况自定义表名
        //...
	}
}

step 2 装饰器注册


var serviceProvider = new ServiceCollection()
  .AddDbContext<TestDbContext>(options =>
  {
	    //使用你的数据库引擎
      options.UseInMemoryDatabase("test");
  })
  //注册装饰器 important!
  .Decorate<TestDbContext>((ctx) => new SoftDeleteDecorator<TestDbContext>(ctx).DbContext)
  .BuildServiceProvider();

step 3 注意事项


//1. 请使用 DbSet.Remove 方法,不可使用批量删除方法:ExecuteDelete(),ExecuteDeleteAsync()


Enjoy !

License

  • MIT

联系我

  • QQ:552175420
  • Email: vipwan#sina.com

项目地址

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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.

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.1 170 9/12/2023
1.1.0 161 9/11/2023
1.0.0 173 9/11/2023 1.0.0 is deprecated because it is no longer maintained.

软删除扩展