Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/EFCore.Relational/Update/ModificationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class ModificationCommand : IModificationCommand, INonTrackedModification
private static readonly bool UseOldBehavior37373 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue37373", out var enabled) && enabled;

private static readonly bool UseOldBehavior37525 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue37525", out var enabled37525) && enabled37525;

/// <summary>
/// Initializes a new <see cref="ModificationCommand" /> instance.
/// </summary>
Expand Down Expand Up @@ -1256,7 +1259,11 @@ public bool TryPropagate(IColumnMappingBase mapping, IUpdateEntry entry)
&& ((!_originalValueInitialized
&& property.GetValueComparer().Equals(
Update.ColumnModification.GetCurrentValue(entry, property),
property.Sentinel))
property.Sentinel)
&& (UseOldBehavior37525
|| !mapping.Column.ProviderValueComparer.Equals(
_currentValue,
Update.ColumnModification.GetCurrentProviderValue(entry, property))))
|| (_originalValueInitialized
&& mapping.Column.ProviderValueComparer.Equals(
Update.ColumnModification.GetCurrentProviderValue(entry, property),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,30 @@ public virtual Task Update_non_indexed_values()
});
}

[ConditionalTheory, InlineData(false), InlineData(true)] // Issue #37525
public virtual async Task Can_save_owned_entity_with_default_values_in_TPH_with_shared_columns(bool async)
=> await ExecuteWithStrategyInTransactionAsync(
async context =>
{
var entity = new CrunchyNougat { Name = "Test" };
context.Add(entity);
_ = async ? await context.SaveChangesAsync() : context.SaveChanges();
},
async context =>
{
var entity = await context.Set<CrunchyNougat>().SingleAsync();
Assert.Null(entity.Filling);
entity.Filling = new NougatFilling();
_ = async ? await context.SaveChangesAsync() : context.SaveChanges();
},
async context =>
{
var entity = await context.Set<CrunchyNougat>().SingleAsync();
Assert.NotNull(entity.Filling);
Assert.Equal(NougatFillingKind.Unknown, entity.Filling.Kind);
Assert.False(entity.Filling.IsFresh);
});

[ConditionalFact]
public abstract void Identifiers_are_generated_correctly();

Expand Down Expand Up @@ -301,6 +325,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
.HasColumnName("ZipCode");
});

modelBuilder.Entity<CrunchyNougat>(b =>
{
b.OwnsOne(e => e.Filling, ob =>
{
ob.Property(o => o.Kind).HasColumnName("FillingKind");
ob.Property(o => o.IsFresh).HasColumnName("FillingIsFresh");
});
});
modelBuilder.Entity<SoftNougat>(b =>
{
b.OwnsOne(e => e.Filling, ob =>
{
ob.Property(o => o.Kind).HasColumnName("FillingKind");
ob.Property(o => o.IsFresh).HasColumnName("FillingIsFresh");
});
});

modelBuilder
.Entity<
LoginEntityTypeWithAnExtremelyLongAndOverlyConvolutedNameThatIsUsedToVerifyThatTheStoreIdentifierGenerationLengthLimitIsWorkingCorrectlyDetails
Expand Down
35 changes: 35 additions & 0 deletions test/EFCore.Specification.Tests/TestModels/UpdatesModel/Nougat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.TestModels.UpdatesModel;

#nullable disable

public abstract class Nougat
{
public int Id { get; set; }
public string Name { get; set; }
}

public class CrunchyNougat : Nougat
{
public NougatFilling Filling { get; set; }
}

public class SoftNougat : Nougat
{
public NougatFilling Filling { get; set; }
}

public class NougatFilling
{
public NougatFillingKind Kind { get; set; }
public bool IsFresh { get; set; }
}

public enum NougatFillingKind
{
Unknown = 0,
Peanut = 1,
Almond = 2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class UpdatesContext(DbContextOptions options) : PoolableDbContext(option
public DbSet<ProductTableWithView> ProductTable { get; set; } = null!;
public DbSet<ProductTableView> ProductTableView { get; set; } = null!;
public DbSet<Rodney> Trotters { get; set; } = null!;
public DbSet<CrunchyNougat> CrunchyNougats { get; set; } = null!;
public DbSet<SoftNougat> SoftNougats { get; set; } = null!;

public static Task SeedAsync(UpdatesContext context)
{
Expand Down
16 changes: 16 additions & 0 deletions test/EFCore.Specification.Tests/Update/UpdatesTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,22 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
modelBuilder.Entity<LiftObscurer>().HasOne<Lift>().WithOne(x => x.Obscurer).HasForeignKey<LiftObscurer>(e => e.LiftId);
modelBuilder.Entity<LiftBag>();
modelBuilder.Entity<LiftPaper>();

modelBuilder.Entity<Nougat>();
modelBuilder.Entity<CrunchyNougat>(b =>
{
b.OwnsOne(e => e.Filling, ob =>
{
ob.Property(o => o.Kind).HasConversion<string>();
});
});
modelBuilder.Entity<SoftNougat>(b =>
{
b.OwnsOne(e => e.Filling, ob =>
{
ob.Property(o => o.Kind).HasConversion<string>();
});
});
}

protected override Task SeedAsync(UpdatesContext context)
Expand Down