WaybackMachine 1.0.2
See the version list below for details.
dotnet add package WaybackMachine --version 1.0.2
NuGet\Install-Package WaybackMachine -Version 1.0.2
<PackageReference Include="WaybackMachine" Version="1.0.2" />
paket add WaybackMachine --version 1.0.2
#r "nuget: WaybackMachine, 1.0.2"
// 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
- The database context will have to implement the
IWaybackContext
interface
public class DatabaseContext : DbContext, IWaybackContext
- 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; }
- It will also implement the
BaseSaveChanges
method. Implement that method like so
public int BaseSaveChanges() => base.SaveChanges();
- In the
OnModelCreating
method, call the extension methodWaybackMachine.WaybackDbContextExtension.ConfigureWaybackModel
this.ConfigureWaybackModel(modelBuilder);
- Override the
SaveChanges
method of the database context to call the extension methodWaybackMachine.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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- Castle.Core (>= 5.1.1)
- Microsoft.EntityFrameworkCore (>= 7.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.