Skip to content

Commit

Permalink
Override SaveChangesAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
linwenda committed Apr 7, 2023
1 parent 284e18b commit 11894c8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Wax.Core/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : ba
{
}

public bool HasEntitiesChanged { get; private set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseInMemoryDatabase("__wax_database");
Expand All @@ -18,9 +20,17 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(typeof(CustomerEntityTypeConfiguration).Assembly);
}

public bool HasEntitiesChanged { get; private set; }



public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
{
var result = base.SaveChangesAsync(cancellationToken);

HasEntitiesChanged = false;

return result;
}

public async Task ChangeEntitiesAsync(bool saveNow = false, CancellationToken cancellationToken = default)
{
HasEntitiesChanged = true;
Expand Down

0 comments on commit 11894c8

Please sign in to comment.