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

[5.0.3] Correctly distinguish between seeds for different owned types #23863

Merged
merged 2 commits into from
Jan 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ protected virtual Dictionary<IEntityType, List<ITable>> DiffData(
principalSourceTable = mainSourceEntityType.GetTableMappings().First().Table;
}

var useOldBehavior = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue23792", out var enabled) && enabled;
foreach (var sourceSeed in sourceEntityType.GetSeedData())
{
var sourceEntry = GetEntry(sourceSeed, sourceEntityType, _sourceUpdateAdapter);
Expand Down Expand Up @@ -1984,7 +1985,8 @@ protected virtual Dictionary<IEntityType, List<ITable>> DiffData(
if (sourceProperty == null)
{
if (targetProperty.GetAfterSaveBehavior() != PropertySaveBehavior.Save
&& (targetProperty.ValueGenerated & ValueGenerated.OnUpdate) == 0)
&& (targetProperty.ValueGenerated & ValueGenerated.OnUpdate) == 0
&& (useOldBehavior || targetKeyMap.Count == 1 || entry.EntityType.Name == sourceEntityType.Name))
{
entryMapping.RecreateRow = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8217,6 +8217,98 @@ public void Update_AK_seed_value_with_a_referencing_foreign_key()
}));
}

[ConditionalFact]
public void SeedData_with_guid_AK_and_multiple_owned_types()
{
Execute(
target =>
{
target.Entity<SomeEntity>(
builder =>
{
builder.HasAlternateKey(x => x.Guid);
builder.Property(x => x.Id).ValueGeneratedNever();

var data = new[]
{
new SomeEntity(1L, new Guid("74520CF7-0C78-447C-8FE0-ED97A16A13F5"))
};

var owned = data.Select(x => new
{
SomeEntityId = x.Id,
}).ToArray();

builder.OwnsOne(x => x.OwnedEntity).HasData(owned);
builder.HasData(data);
});

target.Entity<ApplicationUser>(
builder => {
builder.HasAlternateKey(x => x.Guid);

var data = new[]
{
new ApplicationUser()
{
Id = 12345,
Guid = new Guid("4C85B629-732A-4724-AA33-6E8108134BAE")
}
};

var owned = data.Select(x => new
{
ApplicationUserId = x.Id,
}).ToArray();

builder.OwnsOne(x => x.OwnedEntity).HasData(owned);
builder.HasData(data);
});
},
target => { },
source => { },
Assert.Empty,
Assert.Empty);
}

protected class SomeEntity
{
public SomeEntity(long id, Guid guid)
{
Id = id;
Guid = guid;
}

public virtual SomeOwnedEntity OwnedEntity { get; private set; } = new SomeOwnedEntity();

public Guid Guid { get; protected set; }

public long Id { get; protected set; }

}

protected class ApplicationUser
{
private readonly SomeOwnedEntity _ownedEntity;


public ApplicationUser()
{
_ownedEntity = null!;
}

public virtual long Id { get; set; }

public virtual SomeOwnedEntity OwnedEntity => _ownedEntity;

public Guid Guid { get; set; }

}

protected class SomeOwnedEntity
{
}

[ConditionalFact]
public void SeedData_and_PK_rename()
{
Expand Down