Skip to content

Commit

Permalink
Merge in 'release/5.0' changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnet-bot committed Jan 14, 2021
2 parents ff5f100 + f28edd3 commit efc2924
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ protected virtual IEnumerable<MigrationOperation> Remove([NotNull] ISequence sou
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 IEnumerable<MigrationOperation> Remove([NotNull] ISequence sou
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

0 comments on commit efc2924

Please sign in to comment.