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 complex type support to the update pipeline #31409

Merged
merged 1 commit into from
Aug 7, 2023
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
34 changes: 17 additions & 17 deletions src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ protected virtual void GenerateSequence(
if (sequence.Type != Sequence.DefaultClrType)
{
sequenceBuilderNameBuilder
.Append("<")
.Append('<')
.Append(Code.Reference(sequence.Type))
.Append(">");
.Append('>');
}

sequenceBuilderNameBuilder
.Append("(")
.Append('(')
.Append(Code.Literal(sequence.Name));

if (!string.IsNullOrEmpty(sequence.ModelSchema))
Expand All @@ -331,7 +331,7 @@ protected virtual void GenerateSequence(
.Append(Code.Literal(sequence.ModelSchema));
}

sequenceBuilderNameBuilder.Append(")");
sequenceBuilderNameBuilder.Append(')');
var sequenceBuilderName = sequenceBuilderNameBuilder.ToString();

stringBuilder
Expand All @@ -347,7 +347,7 @@ protected virtual void GenerateSequence(
.AppendLine()
.Append(".StartsAt(")
.Append(Code.Literal(sequence.StartValue))
.Append(")");
.Append(')');
}

if (sequence.IncrementBy != Sequence.DefaultIncrementBy)
Expand All @@ -356,7 +356,7 @@ protected virtual void GenerateSequence(
.AppendLine()
.Append(".IncrementsBy(")
.Append(Code.Literal(sequence.IncrementBy))
.Append(")");
.Append(')');
}

if (sequence.MinValue != Sequence.DefaultMinValue)
Expand All @@ -374,7 +374,7 @@ protected virtual void GenerateSequence(
.AppendLine()
.Append(".HasMax(")
.Append(Code.Literal(sequence.MaxValue))
.Append(")");
.Append(')');
}

if (sequence.IsCyclic != Sequence.DefaultIsCyclic)
Expand Down Expand Up @@ -586,7 +586,7 @@ protected virtual void GenerateComplexProperty(

private static string GenerateNestedBuilderName(string builderName)
{
if (builderName.StartsWith("b", StringComparison.Ordinal))
if (builderName.StartsWith('b'))
{
// ReSharper disable once InlineOutVariableDeclaration
var counter = 1;
Expand Down Expand Up @@ -876,7 +876,7 @@ protected virtual void GenerateEntityTypeAnnotations(
stringBuilder
.AppendLine()
.Append(entityTypeBuilderName)
.Append(".")
.Append('.')
.Append("HasDiscriminator");

if (discriminatorPropertyAnnotation?.Value != null)
Expand All @@ -886,11 +886,11 @@ protected virtual void GenerateEntityTypeAnnotations(
.MakeNullable(discriminatorProperty.IsNullable)
?? discriminatorProperty.ClrType;
stringBuilder
.Append("<")
.Append('<')
.Append(Code.Reference(propertyClrType))
.Append(">(")
.Append(Code.Literal((string)discriminatorPropertyAnnotation.Value))
.Append(")");
.Append(')');
}
else
{
Expand All @@ -903,11 +903,11 @@ protected virtual void GenerateEntityTypeAnnotations(
var value = (bool)discriminatorMappingCompleteAnnotation.Value;

stringBuilder
.Append(".")
.Append('.')
.Append("IsComplete")
.Append("(")
.Append('(')
.Append(Code.Literal(value))
.Append(")");
.Append(')');
}

if (discriminatorValueAnnotation?.Value != null)
Expand All @@ -924,11 +924,11 @@ protected virtual void GenerateEntityTypeAnnotations(
}

stringBuilder
.Append(".")
.Append('.')
.Append("HasValue")
.Append("(")
.Append('(')
.Append(Code.UnknownLiteral(value))
.Append(")");
.Append(')');
}

stringBuilder.AppendLine(";");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore.Scaffolding.Internal;
Expand Down Expand Up @@ -652,7 +651,7 @@ private void Create(IEntityType entityType, CSharpRuntimeAnnotationCodeGenerator
mainBuilder.AppendLine(",")
.Append("indexerPropertyInfo: RuntimeEntityType.FindIndexerProperty(")
.Append(_code.Literal(entityType.ClrType))
.Append(")");
.Append(')');
}

if (entityType.IsPropertyBag)
Expand Down Expand Up @@ -991,7 +990,7 @@ private void PropertyBaseParameters(
.Append(".GetProperty(")
.Append(_code.Literal(propertyInfo.Name))
.Append(", ")
.Append(propertyInfo.GetAccessors().Any() ? "BindingFlags.Public" : "BindingFlags.NonPublic")
.Append(propertyInfo.GetAccessors().Length != 0 ? "BindingFlags.Public" : "BindingFlags.NonPublic")
.Append(propertyInfo.IsStatic() ? " | BindingFlags.Static" : " | BindingFlags.Instance")
.Append(" | BindingFlags.DeclaredOnly)");
}
Expand Down Expand Up @@ -1055,12 +1054,12 @@ private void FindProperties(
.Append(entityTypeVariable)
.Append(".FindProperty(")
.Append(_code.Literal(property.Name))
.Append(")");
.Append(')');

if (nullable)
{
mainBuilder
.Append("!");
.Append('!');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public virtual void ProcessModelFinalizing(
var storeObject = StoreObjectIdentifier.Table(tableName, schema);
foreach (var entityType in conventionEntityTypes)
{
TryUniquifyColumnNames(entityType, columns, storeObject, maxLength);
TryUniquifyKeyNames(entityType, keys, storeObject, maxLength);
TryUniquifyForeignKeyNames(entityType, foreignKeys, storeObject, maxLength);
TryUniquifyIndexNames(entityType, indexes, storeObject, maxLength);
TryUniquifyCheckConstraintNames(entityType, checkConstraints, storeObject, maxLength);
TryUniquifyTriggerNames(entityType, triggers, storeObject, maxLength);
UniquifyColumnNames(entityType, columns, storeObject, maxLength);
UniquifyKeyNames(entityType, keys, storeObject, maxLength);
UniquifyForeignKeyNames(entityType, foreignKeys, storeObject, maxLength);
UniquifyIndexNames(entityType, indexes, storeObject, maxLength);
UniquifyCheckConstraintNames(entityType, checkConstraints, storeObject, maxLength);
UniquifyTriggerNames(entityType, triggers, storeObject, maxLength);
}
}
}
Expand Down Expand Up @@ -210,13 +210,13 @@ private static void TryUniquifyTableNames(
}
}

private static void TryUniquifyColumnNames(
private static void UniquifyColumnNames(
IConventionTypeBase type,
Dictionary<string, IConventionProperty> columns,
in StoreObjectIdentifier storeObject,
int maxLength)
{
foreach (var property in type.GetDeclaredProperties())
foreach (var property in type.GetProperties())
{
var columnName = property.GetColumnName(storeObject);
if (columnName == null)
Expand All @@ -230,20 +230,28 @@ private static void TryUniquifyColumnNames(
continue;
}

if (property == otherProperty)
{
continue;
}

var identifyingMemberInfo = property.PropertyInfo ?? (MemberInfo?)property.FieldInfo;
if ((identifyingMemberInfo != null
&& identifyingMemberInfo.IsSameAs(otherProperty.PropertyInfo ?? (MemberInfo?)otherProperty.FieldInfo))
|| (property.IsPrimaryKey() && otherProperty.IsPrimaryKey())
|| (property.IsConcurrencyToken && otherProperty.IsConcurrencyToken)
|| (!property.Builder.CanSetColumnName(null) && !otherProperty.Builder.CanSetColumnName(null)))
{
// Handle this with a default value convention #9329
if (property.GetAfterSaveBehavior() == PropertySaveBehavior.Save
&& otherProperty.GetAfterSaveBehavior() == PropertySaveBehavior.Save
&& property.ValueGenerated is ValueGenerated.Never or ValueGenerated.OnUpdateSometimes
&& otherProperty.ValueGenerated is ValueGenerated.Never or ValueGenerated.OnUpdateSometimes)
&& property.ValueGenerated is ValueGenerated.Never or ValueGenerated.OnUpdateSometimes)
{
// Handle this with a default value convention #9329
property.Builder.ValueGenerated(ValueGenerated.OnUpdateSometimes);
}

if (otherProperty.GetAfterSaveBehavior() == PropertySaveBehavior.Save
&& otherProperty.ValueGenerated is ValueGenerated.Never or ValueGenerated.OnUpdateSometimes)
{
otherProperty.Builder.ValueGenerated(ValueGenerated.OnUpdateSometimes);
}

Expand Down Expand Up @@ -280,7 +288,7 @@ private static void TryUniquifyColumnNames(

foreach (var complexProperty in type.GetDeclaredComplexProperties())
{
TryUniquifyColumnNames(complexProperty.ComplexType, columns, storeObject, maxLength);
UniquifyColumnNames(complexProperty.ComplexType, columns, storeObject, maxLength);
}
}

Expand Down Expand Up @@ -317,7 +325,7 @@ private static void TryUniquifyColumnNames(
return null;
}

private void TryUniquifyKeyNames(
private void UniquifyKeyNames(
IConventionEntityType entityType,
Dictionary<string, (IConventionKey, StoreObjectIdentifier)> keys,
in StoreObjectIdentifier storeObject,
Expand Down Expand Up @@ -391,7 +399,7 @@ protected virtual bool AreCompatible(
return null;
}

private void TryUniquifyIndexNames(
private void UniquifyIndexNames(
IConventionEntityType entityType,
Dictionary<string, (IConventionIndex, StoreObjectIdentifier)> indexes,
in StoreObjectIdentifier storeObject,
Expand Down Expand Up @@ -463,7 +471,7 @@ protected virtual bool AreCompatible(
return null;
}

private void TryUniquifyForeignKeyNames(
private void UniquifyForeignKeyNames(
IConventionEntityType entityType,
Dictionary<string, (IConventionForeignKey, StoreObjectIdentifier)> foreignKeys,
in StoreObjectIdentifier storeObject,
Expand Down Expand Up @@ -556,7 +564,7 @@ protected virtual bool AreCompatible(
return null;
}

private void TryUniquifyCheckConstraintNames(
private void UniquifyCheckConstraintNames(
IConventionEntityType entityType,
Dictionary<(string, string?), (IConventionCheckConstraint, StoreObjectIdentifier)> checkConstraints,
in StoreObjectIdentifier storeObject,
Expand Down Expand Up @@ -629,7 +637,7 @@ protected virtual bool AreCompatible(
return null;
}

private void TryUniquifyTriggerNames(
private void UniquifyTriggerNames(
IConventionEntityType entityType,
Dictionary<string, (IConventionTrigger, StoreObjectIdentifier)> triggers,
in StoreObjectIdentifier storeObject,
Expand Down
Loading