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

Add failing test which fails to SetValues of owned property #24504

Closed
wants to merge 1 commit into from
Closed
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
49 changes: 49 additions & 0 deletions test/EFCore.Tests/ChangeTracking/PropertyEntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,55 @@ protected internal override void OnModelCreating(ModelBuilder modelBuilder)
}
}

[ConditionalFact]
public void SetValues_to_owned_property()
{
Guid id;
using (var context = new OwnedDbContext())
{
id = context.Add(new Owner { OwnerInt = 1, Owned = new() { OwnedInt = 1 } }).Entity.Id;
context.SaveChanges();
}

var disconnectedEntity = new Owner { Id = id, OwnerInt = 2, Owned = new() { OwnedInt = 2 } };


using (var context = new OwnedDbContext())
{
var trackedEntity = context.Find<Owner>(id);
var entry = context.Entry(trackedEntity);
entry.CurrentValues.SetValues(disconnectedEntity);

Assert.Equal(2, trackedEntity.OwnerInt);
Assert.Equal(2, trackedEntity.Owned.OwnedInt);

context.SaveChanges();
}
}

public class Owner
{
public Guid Id { get; set; }
public int OwnerInt { get; set; }
public Owned Owned { get; set; } = null!;
}


[Owned]
public class Owned
{
public int OwnedInt { get; set; }
}

protected class OwnedDbContext : DbContext
{
protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseInMemoryDatabase(GetType().FullName);

public DbSet<Owner> Owners { get; set; } = null!;
}


[ConditionalFact]
public void Setting_IsModified_is_not_reset_by_OriginalValues()
{
Expand Down