Skip to content

Commit

Permalink
Add TPC support for data seeding
Browse files Browse the repository at this point in the history
Use row-based diffing for data seeding

Part of #3170
Fixes #22063
Fixes #12466
Fixes #27575
  • Loading branch information
AndriySvyryd committed Apr 29, 2022
1 parent 2272257 commit 0dc7cad
Show file tree
Hide file tree
Showing 52 changed files with 1,954 additions and 1,384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public override void Generate(IProperty property, CSharpRuntimeAnnotationCodeGen
mainBuilder
.Append("var ").Append(overrideVariable).AppendLine(" = new RuntimeRelationalPropertyOverrides(").IncrementIndent()
.Append(parameters.TargetName).AppendLine(",")
.Append(code.Literal(overrides.ColumnNameOverriden)).AppendLine(",")
.Append(code.Literal(overrides.ColumnNameOverridden)).AppendLine(",")
.Append(code.UnknownLiteral(overrides.ColumnName)).AppendLine(");").DecrementIndent();

CreateAnnotations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static string GetColumnBaseName(this IReadOnlyProperty property)
public static string? GetColumnName(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
var overrides = RelationalPropertyOverrides.Find(property, storeObject);
if (overrides?.ColumnNameOverriden == true)
if (overrides?.ColumnNameOverridden == true)
{
return overrides.ColumnName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class EntityFrameworkRelationalServicesBuilder : EntityFrameworkServicesB
{ typeof(IRowKeyValueFactoryFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IRowForeignKeyValueFactoryFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IRowIndexValueFactoryFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IRowIdentityMapFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IParameterNameGeneratorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IComparer<IReadOnlyModificationCommand>), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IMigrationsIdGenerator), new ServiceCharacteristics(ServiceLifetime.Singleton) },
Expand Down Expand Up @@ -130,6 +131,7 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
TryAdd<IRowKeyValueFactoryFactory, RowKeyValueFactoryFactory>();
TryAdd<IRowForeignKeyValueFactoryFactory, RowForeignKeyValueFactoryFactory>();
TryAdd<IRowIndexValueFactoryFactory, RowIndexValueFactoryFactory>();
TryAdd<IRowIdentityMapFactory, RowIdentityMapFactory>();
TryAdd<IModelCustomizer, RelationalModelCustomizer>();
TryAdd<IModelRuntimeInitializer, RelationalModelRuntimeInitializer>();
TryAdd<IRelationalAnnotationProvider, RelationalAnnotationProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private static RuntimeSequence Create(ISequence sequence, RuntimeModel runtimeMo
RuntimeProperty runtimeProperty)
=> new(
runtimeProperty,
propertyOverrides.ColumnNameOverriden,
propertyOverrides.ColumnNameOverridden,
propertyOverrides.ColumnName);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ public interface IRelationalPropertyOverrides : IAnnotatable
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
bool ColumnNameOverriden { get; }
bool ColumnNameOverridden { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override bool IsReadOnly
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual bool ColumnNameOverriden
public virtual bool ColumnNameOverridden
=> _columnNameConfigurationSource != null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Metadata.Internal;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public sealed class TableBaseIdentityComparer : IEqualityComparer<ITableBase>
{
private TableBaseIdentityComparer()
{
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public static readonly TableBaseIdentityComparer Instance = new();

/// <inheritdoc />
public bool Equals(ITableBase? x, ITableBase? y)
=> ReferenceEquals(x, y)
|| (x is null
? y is null
: y is not null && x.Name == y.Name && x.Schema == y.Schema);

/// <inheritdoc />
public int GetHashCode(ITableBase obj)
=> HashCode.Combine(obj.Name, obj.Schema);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class RuntimeRelationalPropertyOverrides : AnnotatableBase, IRelationalPr
/// Initializes a new instance of the <see cref="RuntimeRelationalPropertyOverrides" /> class.
/// </summary>
/// <param name="property">The property for which the overrides are applied.</param>
/// <param name="columnNameOverriden">Whether the column name is overridden.</param>
/// <param name="columnNameOverridden">Whether the column name is overridden.</param>
/// <param name="columnName">The column name.</param>
public RuntimeRelationalPropertyOverrides(
RuntimeProperty property,
bool columnNameOverriden,
bool columnNameOverridden,
string? columnName)
{
Property = property;
if (columnNameOverriden)
if (columnNameOverridden)
{
SetAnnotation(RelationalAnnotationNames.ColumnName, columnName);
}
Expand All @@ -51,7 +51,7 @@ IProperty IRelationalPropertyOverrides.Property
}

/// <inheritdoc />
bool IRelationalPropertyOverrides.ColumnNameOverriden
bool IRelationalPropertyOverrides.ColumnNameOverridden
{
[DebuggerStepThrough]
get => FindAnnotation(RelationalAnnotationNames.ColumnName) != null;
Expand Down

0 comments on commit 0dc7cad

Please sign in to comment.