Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete correct shared-key entity with in-memory provider #28979

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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