Fur.ExtensionPack 0.0.10-rc

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

// Install Fur.ExtensionPack as a Cake Tool
#tool nuget:?package=Fur.ExtensionPack&version=0.0.10-rc&prerelease

Fur.ExtensionPack

Build status Nuget

介绍

针对Fur基础功能的实用拓展包

安装教程
  1. nuget Install-Package Fur.ExtensionPack -Version 0.0.8
使用说明

1. 审计

对于大部分实体,都需要记录实体进入数据库的相关时间,以及操作人员等,目前此扩展包支持实体创建时间和修改时间的自动管理。

使用

将数据库上下文由继承于AppDbContext更改为继承于AuditingDbContext

    [AppDbContext("Sqlite3ConnectionString")]
    public class FurDbContext : AppDbContext<FurDbContext>
    {
        public FurDbContext(DbContextOptions<FurDbContext> options) : base(options)
        {

        }
        protected override void SavingChangesEvent(object sender, SavingChangesEventArgs e)
        {

        }

    }

然后,在需要自动管理时间的实体添加ICreationTime以及IUpdateTime接口

 public class Person : Entity,ICreationTime,IUpdateTime
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public Person()
        {
            CreatedTime = DateTime.Now;
            IsDeleted = false;
        }

        /// <summary>
        /// 姓名
        /// </summary>
        [MaxLength(32)]
        public string Name { get; set; }
        。。。
    }

这样就完成了,此实体新建的时候,将会自动更新创建时间,被更新的时候,写入更新时间,以及在更新的时候,防止创建时间被篡改。

2.修正Mapster的行为

Fur使用Mapster作为Map工具,这是一个非常强大且性能不错的库,然后此库有一些小瑕疵,当子实体列表一并被map作为更新的时候,Mapster是先清空列表,然后再插入列表,这样做是正常的,但是对于EF,它会认为这个子实体被完全修改了,从而为每个子实体生成了全量更新的Sql语句,这对于大型复杂实体来说,对性能的影响是致命性的。要解决这个问题的关键,是让Mapster知道,实体的哪个字段作为主键,并且根据主键去查找对应关系,应此本扩展包提供了一个AdaptToTrack拓展方法能够很方便地进行调用。

public async Task Update(PersonInputDto input)
{
  var person = await _personRepository.Entities.Include(u => u.PersonDetail).Include(u => u.Childrens).Include(u => u.Posts).SingleAsync(u => u.Id == input.Id.Value);
//直接Adapt,会清空Children列表然后插入,EF将会捕捉到所有Children被更新
// input.Adapt(person);
//AdaptToTrack会检测Children的主键(Id)的对应关系,来进行Map,EF只会捕捉到被修改过的更新
   input.AdaptToTrack(person);
   await _personRepository.UpdateAsync(person);

}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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.
  • net5.0

    • Fur (>= 1.0.0-rc.final.2)

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Fur.ExtensionPack:

Package Downloads
Fur.ExtensionPack.Ideneity

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.92-rc 214 10/19/2020
0.0.85-rc 258 10/18/2020
0.0.47-rc 228 10/16/2020
0.0.42-rc 183 10/16/2020
0.0.39-rc 187 10/16/2020
0.0.35-rc 200 10/16/2020
0.0.34-rc 199 10/16/2020
0.0.18-rc 194 10/16/2020
0.0.17-rc 207 10/16/2020
0.0.15-rc 204 10/16/2020
0.0.13-rc 201 10/15/2020
0.0.12-rc 198 10/15/2020
0.0.11-rc 230 10/15/2020
0.0.10-rc 200 10/15/2020