EFTimestamps.Annotations 1.0.0

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

// Install EFTimestamps.Annotations as a Cake Tool
#tool nuget:?package=EFTimestamps.Annotations&version=1.0.0

EFTimestamps

NuGet version Downloads

Put timestamps in your entities the easy way

Motivation

Using timestamps is something I do in almost every app I make, if you're here probably you do too. Since I always follow the same approach to implement them I just ended up making this library in order not to have to rewrite this code ever again. Hopefully you'll be able to find some use for it too!

Quick start

Install both EFTimestamps.Annotations and EFTimestamps.Configuration. It is divided in two libs so that you can have your entities in a separate dll that does not know about EFCore.

After that, just mark your timestamp props with the data annotations, you don't need to use both timestamps for it to work!

using EFTimestamps.Annotations;
using System;

public class TestEntity
{
    [CreatedAt]
    public DateTime CreatedAt { get; set; }

    [UpdatedAt]
    public DateTime UpdatedAt { get; set; }
}

Then, go to your DbContext and override the variant of SaveChanges or SaveChangesAsync that you use in your persistence layer. If you just use your context directly with no intermediary feel free to override all of them. In case it helps, here are all the methods you may need to override and how to override them 🙃

using EFTimestamps.Configuration;
using Microsoft.EntityFrameworkCore;
using System.Threading;
using System.Threading.Tasks;

public class TestContext : DbContext
{
    public override int SaveChanges()
    {
        this.UpdateTimestamps();
        return base.SaveChanges();
    }

    public override int SaveChanges(bool acceptAllChangesOnSuccess)
    {
        this.UpdateTimestamps();
        return base.SaveChanges(acceptAllChangesOnSuccess);
    }

    public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default(CancellationToken))
    {
        this.UpdateTimestamps();
        return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
    }

    public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
    {
        this.UpdateTimestamps();
        return base.SaveChangesAsync(cancellationToken);
    }
}

Changelog

  • 1.0.0 - First release
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on EFTimestamps.Annotations:

Package Downloads
EFTimestamps.Configuration

Extensions for the DbContext class to configure the annotations provided in EFTimestamps.Annotations

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 537 9/25/2022
1.0.1 647 4/20/2020
1.0.0 548 4/14/2020

First release! 😎