WaybackMachine 1.0.2

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

// Install WaybackMachine as a Cake Tool
#tool nuget:?package=WaybackMachine&version=1.0.2

Entity Framework Core : Wayback 🕝

A small library that implements a way to revert an EFCore object to a previous state. The entities returned by the WayBack class are Castle.Core.Proxies proxies. That allows lazy loading just like EFCore, however the lazy loaded entities are also reverted back in time to the same point as the parent entity.

Usage

var context = new DatabaseContext();
// Create a new entity and save it to the database
var sam = new User() {
    Name = "Sammy"
};
context.Users.Add(sam);
context.SaveChanges();

// Save the revert time point and
// then make some modifications and save
var revertPoint = DateTime.Now;
sam.Name = "Sam";
context.SaveChanges();

// Create a new wayback instance with
// a fresh database context and the revert time
// and get the old version of the entity
var wayback = WayBack.CreateWayBack(new DatabaseContext(), revertPoint);
var oldsam = wayback.GetEntity<User>(s => s.Name == "Sam");
Console.WriteLine($"Old Name : {oldsam.Name}");

// Prints : Old Name : Sammy

Setup

  1. The database context will have to implement the IWaybackContext interface
public class DatabaseContext : DbContext, IWaybackContext  
  1. The interface will require you to implement three fields. Implement them like so
public DbContext InternalDbContext => this;
public DbSet<AuditRecord> AuditEntries { get; set; }
public DbSet<AuditTransactionRecord> AuditTransactions { get; set; }
  1. It will also implement the BaseSaveChanges method. Implement that method like so
public int BaseSaveChanges() => base.SaveChanges();		
  1. In the OnModelCreating method, call the extension method WaybackMachine.WaybackDbContextExtension.ConfigureWaybackModel
this.ConfigureWaybackModel(modelBuilder);
  1. Override the SaveChanges method of the database context to call the extension method WaybackMachine.WaybackDbContextExtension.SaveChangesWithTracking like so. This step is optional
public override int SaveChanges() => this.SaveChangesWithTracking();

Attributes

DoNotAudit : Properties with this attribute will not be audited and tracked

CensorAudit : Properties with this attribute will only have the hashes saved. Only works for byte[] and string

JunctionTable : This indicates to Wayback that a class is a junction for handling Many-To-Many relationships

Audit : This indicates to Wayback that an entity should be audited and tracked

SoftDelete : This indicates that entities have to be soft deleted instead of hard deletes. If this attribute is added to an entity, then it implemented a bool IsDeleted parameter. If this attribute is implemented, the OnModelCreating method will also implement a Query filter on it

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.8.9 119 1/24/2024
1.8.8 76 1/24/2024
1.8.6 116 1/14/2024
1.8.0 100 12/26/2023
1.5.2 139 7/16/2023
1.0.2 139 7/6/2023
1.0.0 161 7/6/2023