EntityFrameworkCore.ChangeEvents
0.9.0
dotnet add package EntityFrameworkCore.ChangeEvents --version 0.9.0
NuGet\Install-Package EntityFrameworkCore.ChangeEvents -Version 0.9.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="EntityFrameworkCore.ChangeEvents" Version="0.9.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EntityFrameworkCore.ChangeEvents" Version="0.9.0" />
<PackageReference Include="EntityFrameworkCore.ChangeEvents" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EntityFrameworkCore.ChangeEvents --version 0.9.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EntityFrameworkCore.ChangeEvents, 0.9.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.
#:package EntityFrameworkCore.ChangeEvents@0.9.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EntityFrameworkCore.ChangeEvents&version=0.9.0
#tool nuget:?package=EntityFrameworkCore.ChangeEvents&version=0.9.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EntityFrameworkCore.ChangeEvents
Automatic change events for entity framework core.
Features
- Configure once, no way to forget to track changes
- Tracks old and new state
- Tracks success and failure of
SaveChanges()
- Database provider agnostic
Installation
Install with dotnet cli
Add package
dotnet add package EntityFrameworkCore.ChangeEvents
After setup (see below), remember to run and apply migrations
dotnet ef migrations add ChangeEvents
dotnet ef database update
Usage/Examples
Minimal setup
public class SampleContext : DbContext
{
public SampleContext(DbContextOptions<SampleContext> options)
: base(options)
{
}
public DbSet<WeatherForecast> WeatherForecasts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Add the change event interceptor.
optionsBuilder.UseChangeEvents();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Add change event model.
modelBuilder.AddChangeEvents<ChangeEvent>();
}
}
Exclude types from being tracked
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Add the change event interceptor, exclude TypeToExclude from change tracking
optionsBuilder.UseChangeEvents(options =>
options.ExclusionFilter = type => type == typeof(TypeToExlude));
}
Customize JSON serializer
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Add the change event interceptor, customize JSON serializer
optionsBuilder.UseChangeEvents(options =>
options.JsonSerializerOptions.Converters.Insert(0, new JsonStringEnumConverter()));
}
Customize Entity framework model
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Add change event model, create index on IsPublished
modelBuilder.AddChangeEvents<ChangeEvent>(e =>
e.HasIndex(x => x.IsPublished));
}
Omit (foreign) keys from change events
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Omit primary and foreign keys from change events
optionsBuilder.UseChangeEvents(options =>
{
options.OmitPrimaryKeys = true;
options.OmitForeignKeys = true;
});
}
Run sample project locally
Clone the project
git@github.com:mkromkamp/efcore-change-events.git
Navigate to the example project
cd example/EntityFrameworkCore.ChangeEvents.Examples.Api
Bring up docker-compose stack
docker-compose pull
docker-compose up -d --build
Apply migrations
dotnet ef database update
Start the example project
dotnet run
Navigate to the swagger documentation
License
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 is compatible. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.EntityFrameworkCore (>= 6.0.0)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)
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 |
---|---|---|
0.9.0 | 18,795 | 11/19/2023 |
0.8.1 | 21,480 | 5/3/2023 |
0.8.0 | 558 | 4/20/2023 |
0.7.0 | 310 | 3/3/2023 |
0.7.0-beta.3 | 4,095 | 1/31/2023 |
0.7.0-beta.2 | 146 | 1/31/2023 |
0.7.0-beta.1 | 148 | 1/31/2023 |
0.6.0 | 367 | 12/8/2022 |
0.5.0 | 3,864 | 9/20/2022 |
0.4.0 | 512 | 8/5/2022 |
0.3.0 | 491 | 8/3/2022 |
0.2.0 | 469 | 8/2/2022 |
0.1.0 | 508 | 6/26/2022 |