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

IModificationCommand API Review changes #25392

Merged
merged 1 commit into from
Aug 3, 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 @@ -55,7 +55,7 @@ public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServi
{
{ typeof(IKeyValueIndexFactorySource), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IParameterNameGeneratorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IComparer<IModificationCommand>), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IComparer<IReadOnlyModificationCommand>), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IMigrationsIdGenerator), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(ISqlGenerationHelper), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IRelationalAnnotationProvider), new ServiceCharacteristics(ServiceLifetime.Singleton) },
Expand All @@ -75,7 +75,7 @@ public static readonly IDictionary<Type, ServiceCharacteristics> RelationalServi
{ typeof(IRelationalQueryStringFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(ICommandBatchPreparer), new ServiceCharacteristics(ServiceLifetime.Scoped) },
{ typeof(IModificationCommandBatchFactory), new ServiceCharacteristics(ServiceLifetime.Scoped) },
{ typeof(IMutableModificationCommandFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IModificationCommandFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IMigrationsModelDiffer), new ServiceCharacteristics(ServiceLifetime.Scoped) },
{ typeof(IMigrationsSqlGenerator), new ServiceCharacteristics(ServiceLifetime.Scoped) },
{ typeof(IMigrator), new ServiceCharacteristics(ServiceLifetime.Scoped) },
Expand Down Expand Up @@ -133,7 +133,7 @@ protected override ServiceCharacteristics GetServiceCharacteristics(Type service
public override EntityFrameworkServicesBuilder TryAddCoreServices()
{
TryAdd<IParameterNameGeneratorFactory, ParameterNameGeneratorFactory>();
TryAdd<IComparer<IModificationCommand>, ModificationCommandComparer>();
TryAdd<IComparer<IReadOnlyModificationCommand>, ModificationCommandComparer>();
TryAdd<IMigrationsIdGenerator, MigrationsIdGenerator>();
TryAdd<IKeyValueIndexFactorySource, KeyValueIndexFactorySource>();
TryAdd<IModelCustomizer, RelationalModelCustomizer>();
Expand All @@ -150,7 +150,7 @@ public override EntityFrameworkServicesBuilder TryAddCoreServices()
TryAdd<IRelationalCommandBuilderFactory, RelationalCommandBuilderFactory>();
TryAdd<IRawSqlCommandBuilder, RawSqlCommandBuilder>();
TryAdd<ICommandBatchPreparer, CommandBatchPreparer>();
TryAdd<IMutableModificationCommandFactory, MutableModificationCommandFactory>();
TryAdd<IModificationCommandFactory, ModificationCommandFactory>();
TryAdd<IMigrationsModelDiffer, MigrationsModelDiffer>();
TryAdd<IMigrationsSqlGenerator, MigrationsSqlGenerator>();
TryAdd<IExecutionStrategyFactory, RelationalExecutionStrategyFactory>();
Expand Down
12 changes: 6 additions & 6 deletions src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ protected virtual void Generate(
/// <param name="operation"> The data operation to generate commands for. </param>
/// <param name="model"> The model. </param>
/// <returns> The commands that correspond to the given operation. </returns>
protected virtual IEnumerable<IModificationCommand> GenerateModificationCommands(
protected virtual IEnumerable<IReadOnlyModificationCommand> GenerateModificationCommands(
InsertDataOperation operation,
IModel? model)
{
Expand Down Expand Up @@ -976,7 +976,7 @@ protected virtual IEnumerable<IModificationCommand> GenerateModificationCommands

for (var i = 0; i < operation.Values.GetLength(0); i++)
{
var modificationCommand = Dependencies.MutableModificationCommandFactory.CreateModificationCommand(
var modificationCommand = Dependencies.ModificationCommandFactory.CreateModificationCommand(
new ModificationCommandParameters(operation.Table, operation.Schema, SensitiveLoggingEnabled));
for (var j = 0; j < operation.Columns.Length; j++)
{
Expand Down Expand Up @@ -1034,7 +1034,7 @@ protected virtual void Generate(
/// <param name="operation"> The data operation to generate commands for. </param>
/// <param name="model"> The model. </param>
/// <returns> The commands that correspond to the given operation. </returns>
protected virtual IEnumerable<IModificationCommand> GenerateModificationCommands(
protected virtual IEnumerable<IReadOnlyModificationCommand> GenerateModificationCommands(
DeleteDataOperation operation,
IModel? model)
{
Expand Down Expand Up @@ -1067,7 +1067,7 @@ protected virtual IEnumerable<IModificationCommand> GenerateModificationCommands

for (var i = 0; i < operation.KeyValues.GetLength(0); i++)
{
var modificationCommand = Dependencies.MutableModificationCommandFactory.CreateModificationCommand(
var modificationCommand = Dependencies.ModificationCommandFactory.CreateModificationCommand(
new ModificationCommandParameters(operation.Table, operation.Schema, SensitiveLoggingEnabled));
for (var j = 0; j < operation.KeyColumns.Length; j++)
{
Expand Down Expand Up @@ -1125,7 +1125,7 @@ protected virtual void Generate(
/// <param name="operation"> The data operation to generate commands for. </param>
/// <param name="model"> The model. </param>
/// <returns> The commands that correspond to the given operation. </returns>
protected virtual IEnumerable<IModificationCommand> GenerateModificationCommands(
protected virtual IEnumerable<IReadOnlyModificationCommand> GenerateModificationCommands(
UpdateDataOperation operation,
IModel? model)
{
Expand Down Expand Up @@ -1183,7 +1183,7 @@ protected virtual IEnumerable<IModificationCommand> GenerateModificationCommands

for (var i = 0; i < operation.KeyValues.GetLength(0); i++)
{
var modificationCommand = Dependencies.MutableModificationCommandFactory.CreateModificationCommand(
var modificationCommand = Dependencies.ModificationCommandFactory.CreateModificationCommand(
new ModificationCommandParameters(operation.Table, operation.Schema, SensitiveLoggingEnabled));
for (var j = 0; j < operation.KeyColumns.Length; j++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public MigrationsSqlGeneratorDependencies(
ISqlGenerationHelper sqlGenerationHelper,
IRelationalTypeMappingSource typeMappingSource,
ICurrentDbContext currentContext,
IMutableModificationCommandFactory modificationCommandFactory,
IModificationCommandFactory modificationCommandFactory,
ILoggingOptions loggingOptions,
IRelationalCommandDiagnosticsLogger logger,
IDiagnosticsLogger<DbLoggerCategory.Migrations> migrationsLogger)
Expand All @@ -80,7 +80,7 @@ public MigrationsSqlGeneratorDependencies(
UpdateSqlGenerator = updateSqlGenerator;
TypeMappingSource = typeMappingSource;
CurrentContext = currentContext;
MutableModificationCommandFactory = modificationCommandFactory;
ModificationCommandFactory = modificationCommandFactory;
LoggingOptions = loggingOptions;
Logger = logger;
MigrationsLogger = migrationsLogger;
Expand Down Expand Up @@ -112,9 +112,9 @@ public MigrationsSqlGeneratorDependencies(
public ICurrentDbContext CurrentContext { get; init; }

/// <summary>
/// The <see cref="IMutableModificationCommand" /> factory.
/// The <see cref="IModificationCommand" /> factory.
/// </summary>
public IMutableModificationCommandFactory MutableModificationCommandFactory { get; init; }
public IModificationCommandFactory ModificationCommandFactory { get; init; }

/// <summary>
/// The logging options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public virtual IEnumerable<ModificationCommand> GenerateModificationCommands(IMo
? MigrationsModelDiffer.GetMappedProperties(table, KeyColumns)
: null;

var modificationCommandFactory = new MutableModificationCommandFactory();
var modificationCommandFactory = new ModificationCommandFactory();

for (var i = 0; i < KeyValues.GetLength(0); i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public virtual IEnumerable<ModificationCommand> GenerateModificationCommands(IMo
? MigrationsModelDiffer.GetMappedProperties(table, Columns)
: null;

var modificationCommandFactory = new MutableModificationCommandFactory();
var modificationCommandFactory = new ModificationCommandFactory();

for (var i = 0; i < Values.GetLength(0); i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public virtual IEnumerable<ModificationCommand> GenerateModificationCommands(IMo
? MigrationsModelDiffer.GetMappedProperties(table, Columns)
: null;

var modificationCommandFactory = new MutableModificationCommandFactory();
var modificationCommandFactory = new ModificationCommandFactory();

for (var i = 0; i < KeyValues.GetLength(0); i++)
{
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Relational/Properties/TypeForwards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
using System.Runtime.CompilerServices;
using Microsoft.EntityFrameworkCore.Design;

[assembly: TypeForwardedTo(typeof(AttributeCodeFragment))]
[assembly: TypeForwardedTo(typeof(MethodCallCodeFragment))]
[assembly: TypeForwardedTo(typeof(NestedClosureCodeFragment))]
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Update/ColumnModification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Update
/// Implementation of <see cref="IColumnModification" /> interface.
/// </para>
/// <para>
/// Represents an update, insert, or delete operation for a single column. <see cref="IModificationCommand" />
/// Represents an update, insert, or delete operation for a single column. <see cref="IReadOnlyModificationCommand" />
/// contain lists of <see cref="IColumnModification" />.
/// </para>
/// <para>
Expand All @@ -39,7 +39,7 @@ public class ColumnModification : IColumnModification
/// Creates a new <see cref="ColumnModification" /> instance.
/// </summary>
/// <param name="columnModificationParameters"> Creation parameters. </param>
public ColumnModification(ColumnModificationParameters columnModificationParameters)
public ColumnModification(in ColumnModificationParameters columnModificationParameters)
{
ColumnName = columnModificationParameters.ColumnName;
_originalValue = columnModificationParameters.OriginalValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
Expand All @@ -16,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Update
/// This type is typically used by database providers; it is generally not used in application code.
/// </para>
/// </summary>
public sealed record ColumnModificationParameters
public readonly record struct ColumnModificationParameters
{
/// <summary>
/// A delegate for generating parameter names for the update SQL.
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Update/IColumnModification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Update
{
/// <summary>
/// <para>
/// Represents an update, insert, or delete operation for a single column. <see cref="IModificationCommand" />
/// Represents an update, insert, or delete operation for a single column. <see cref="IReadOnlyModificationCommand" />
/// contain lists of <see cref="IColumnModification" />.
/// </para>
/// <para>
Expand Down
51 changes: 10 additions & 41 deletions src/EFCore.Relational/Update/IModificationCommand.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Update
{
/// <summary>
/// <para>
/// Represents a conceptual database command to insert/update/delete a row.
/// Represents a mutable conceptual database command to insert/update/delete a row.
/// </para>
/// <para>
/// This type is typically used by database providers; it is generally not used in application code.
/// </para>
/// </summary>
public interface IModificationCommand
public interface IModificationCommand : IReadOnlyModificationCommand
{
/// <summary>
/// The name of the table containing the data to be modified.
/// </summary>
public string TableName { get; }

/// <summary>
/// The schema containing the table, or <see langword="null" /> to use the default schema.
/// </summary>
public string? Schema { get; }

/// <summary>
/// The list of <see cref="IColumnModification" /> needed to perform the insert, update, or delete.
/// </summary>
public IReadOnlyList<IColumnModification> ColumnModifications { get; }

/// <summary>
/// Indicates whether the database will return values for some mapped properties
/// that will then need to be propagated back to the tracked entities.
/// </summary>
public bool RequiresResultPropagation { get; }

/// <summary>
/// The <see cref="IUpdateEntry" /> that represent the entities that are mapped to the row to update.
/// </summary>
public IReadOnlyList<IUpdateEntry> Entries { get; }

/// <summary>
/// The <see cref="EntityFrameworkCore.EntityState" /> that indicates whether the row will be
/// inserted (<see cref="Microsoft.EntityFrameworkCore.EntityState.Added" />),
/// updated (<see cref="Microsoft.EntityFrameworkCore.EntityState.Modified" />),
/// or deleted ((<see cref="Microsoft.EntityFrameworkCore.EntityState.Deleted" />).
/// Adds an entry to the command.
/// </summary>
public EntityState EntityState { get; }
/// <param name="entry" > Entry object. </param>
/// <param name="mainEntry"> Whether this is the main entry. Only one main entry can be added to a given command. </param>
public void AddEntry(IUpdateEntry entry, bool mainEntry);

/// <summary>
/// Reads values returned from the database in the given <see cref="ValueBuffer" /> and
/// propagates them back to into the appropriate <see cref="IColumnModification" />
/// from which the values can be propagated on to tracked entities.
/// Creates a new <see cref="IColumnModification" /> and add it to this command.
/// </summary>
/// <param name="valueBuffer"> The buffer containing the values read from the database. </param>
public void PropagateResults(ValueBuffer valueBuffer);
/// <param name="columnModificationParameters"> Creation parameters. </param>
/// <returns> The new <see cref="IColumnModification" /> instance. </returns>
IColumnModification AddColumnModification(in ColumnModificationParameters columnModificationParameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.EntityFrameworkCore.Update
{
/// <summary>
/// <para>
/// A service for creating <see cref="IMutableModificationCommand" /> instances.
/// A service for creating <see cref="IModificationCommand" /> instances.
/// </para>
/// <para>
/// This type is typically used by database providers; it is generally not used in application code.
Expand All @@ -18,14 +18,14 @@ namespace Microsoft.EntityFrameworkCore.Update
/// This service cannot depend on services registered as <see cref="ServiceLifetime.Scoped" />.
/// </para>
/// </summary>
public interface IMutableModificationCommandFactory
public interface IModificationCommandFactory
{
/// <summary>
/// Creates a new database CUD command.
/// </summary>
/// <param name="modificationCommandParameters"> The creation parameters. </param>
/// <returns> A new <see cref="IMutableModificationCommand" /> instance. </returns>
IMutableModificationCommand CreateModificationCommand(
ModificationCommandParameters modificationCommandParameters);
/// <returns> A new <see cref="IModificationCommand" /> instance. </returns>
IModificationCommand CreateModificationCommand(
in ModificationCommandParameters modificationCommandParameters);
}
}
30 changes: 0 additions & 30 deletions src/EFCore.Relational/Update/IMutableModificationCommand.cs

This file was deleted.

Loading