Skip to content

Commit

Permalink
Delete correct shared-key entity with in-memory provider (#28979)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Sep 7, 2022
1 parent 3255316 commit 733e043
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public virtual int ExecuteTransaction(
continue;
}

table.Delete(entry, updateLogger);
table.Delete(entry.SharedIdentityEntry, updateLogger);
}

switch (entry.EntityState)
Expand Down
16 changes: 16 additions & 0 deletions test/EFCore.Specification.Tests/TestModels/UpdatesModel/Rodney.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.ComponentModel.DataAnnotations;

namespace Microsoft.EntityFrameworkCore.TestModels.UpdatesModel;

public class Rodney
{
public string Id { get; set; } = null!;

[ConcurrencyCheck]
public DateTime Concurrency { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class UpdatesContext : PoolableDbContext
public DbSet<ProductViewTable> ProductView { get; set; } = null!;
public DbSet<ProductTableWithView> ProductTable { get; set; } = null!;
public DbSet<ProductTableView> ProductTableView { get; set; } = null!;
public DbSet<Rodney> Trotters { get; set; } = null!;

public UpdatesContext(DbContextOptions options)
: base(options)
Expand Down
39 changes: 39 additions & 0 deletions test/EFCore.Specification.Tests/UpdatesTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,45 @@ protected UpdatesTestBase(TFixture fixture)
new object[] { false }
};

[ConditionalTheory] // Issue #25905
[InlineData(false)]
[InlineData(true)]
public virtual async Task Can_delete_and_add_for_same_key(bool async)
=> await ExecuteWithStrategyInTransactionAsync(
async context =>
{
var rodney1 = new Rodney { Id = "SnotAndMarmite", Concurrency = new DateTime(1973, 9, 3) };
if (async)
{
await context.AddAsync(rodney1);
await context.SaveChangesAsync();
}
else
{
context.Add(rodney1);
context.SaveChanges();
}
context.Remove(rodney1);
var rodney2 = new Rodney { Id = "SnotAndMarmite", Concurrency = new DateTime(1973, 9, 4) };
if (async)
{
await context.AddAsync(rodney2);
await context.SaveChangesAsync();
}
else
{
context.Add(rodney2);
context.SaveChanges();
}
Assert.Equal(1, context.ChangeTracker.Entries().Count());
Assert.Equal(EntityState.Unchanged, context.Entry(rodney2).State);
Assert.Equal(EntityState.Detached, context.Entry(rodney1).State);
});
[ConditionalFact]
public virtual void Mutation_of_tracked_values_does_not_mutate_values_in_store()
{
Expand Down

0 comments on commit 733e043

Please sign in to comment.