Skip to content

Commit

Permalink
Make discriminator read-only by default
Browse files Browse the repository at this point in the history
Fixes #21154
  • Loading branch information
ajcvickers authored Jul 29, 2020
1 parent ea25000 commit f3f7551
Show file tree
Hide file tree
Showing 5 changed files with 763 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1922,15 +1922,17 @@ protected virtual Dictionary<IEntityType, List<ITable>> DiffData(
var targetColumn = targetProperty.GetTableColumnMappings()
.FirstOrDefault(m => m.TableMapping.EntityType == entry.EntityType && m.TableMapping.Table == targetTable)?.Column;
var sourceColumn = diffContext.FindSource(targetColumn);
if (sourceColumn == null)
{
continue;
}

var sourceProperty = sourceColumn.PropertyMappings.Select(m => m.Property)
var sourceProperty = sourceColumn?.PropertyMappings.Select(m => m.Property)
.FirstOrDefault(p => p.DeclaringEntityType.IsAssignableFrom(sourceEntityType));
if (sourceProperty == null)
{
if (targetProperty.GetAfterSaveBehavior() != PropertySaveBehavior.Save
&& (targetProperty.ValueGenerated & ValueGenerated.OnUpdate) == 0)
{
entryMapping.RecreateRow = true;
break;
}

continue;
}

Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4112,7 +4112,8 @@ private InternalPropertyBuilder GetOrCreateDiscriminatorProperty(Type type, stri
type ?? discriminatorProperty?.ClrType ?? _defaultDiscriminatorType,
name ?? discriminatorProperty?.Name ?? _defaultDiscriminatorName,
typeConfigurationSource: type != null ? configurationSource : (ConfigurationSource?)null,
configurationSource: configurationSource);
configurationSource)
?.AfterSave(PropertySaveBehavior.Throw, ConfigurationSource.Convention);
}

private DiscriminatorBuilder DiscriminatorBuilder(
Expand Down
Loading

0 comments on commit f3f7551

Please sign in to comment.