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

Fix to #28595 - Use partial updates for JSON #28844

Merged
merged 1 commit into from
Aug 24, 2022
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
6 changes: 4 additions & 2 deletions src/EFCore.Relational/Update/ColumnModification.cs
Original file line number Diff line number Diff line change
@@ -1,8 +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.Data;

namespace Microsoft.EntityFrameworkCore.Update;

/// <summary>
Expand Down Expand Up @@ -54,6 +52,7 @@ public ColumnModification(in ColumnModificationParameters columnModificationPara
IsNullable = columnModificationParameters.IsNullable;
_generateParameterName = columnModificationParameters.GenerateParameterName;
Entry = columnModificationParameters.Entry;
JsonPath = columnModificationParameters.JsonPath;

UseParameter = _generateParameterName != null;
}
Expand Down Expand Up @@ -174,6 +173,9 @@ public virtual object? Value
}
}

/// <inheritdoc />
public virtual string? JsonPath { get; }

/// <inheritdoc />
public virtual void AddSharedColumnModification(IColumnModification modification)
{
Expand Down
60 changes: 58 additions & 2 deletions src/EFCore.Relational/Update/ColumnModificationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public readonly record struct ColumnModificationParameters
/// Indicates whether the column is part of a primary or alternate key.
/// </summary>
public bool IsKey { get; init; }

/// <summary>
/// The column.
/// </summary>
Expand All @@ -92,6 +92,11 @@ public readonly record struct ColumnModificationParameters
/// </summary>
public string? ColumnType { get; init; }

/// <summary>
/// In case of JSON column modification, the JSON path leading to the JSON element that needs to be updated.
/// </summary>
public string? JsonPath { get; init; }

/// <summary>
/// Creates a new <see cref="ColumnModificationParameters" /> instance.
/// </summary>
Expand Down Expand Up @@ -137,8 +142,9 @@ public ColumnModificationParameters(

GenerateParameterName = null;
Entry = null;
JsonPath = null;
}

/// <summary>
/// Creates a new <see cref="ColumnModificationParameters" /> instance.
/// </summary>
Expand Down Expand Up @@ -182,6 +188,7 @@ public ColumnModificationParameters(

GenerateParameterName = null;
Entry = null;
JsonPath = null;
}

/// <summary>
Expand Down Expand Up @@ -225,5 +232,54 @@ public ColumnModificationParameters(

GenerateParameterName = generateParameterName;
Entry = entry;
JsonPath = null;
}

/// <summary>
/// Creates a new <see cref="ColumnModificationParameters" /> instance.
/// </summary>
/// <param name="columnName">The name of the column.</param>
/// <param name="originalValue">The original value of the property mapped to this column.</param>
/// <param name="value">The current value of the property mapped to this column.</param>
/// <param name="jsonPath">The JSON path leading to the JSON element that needs to be updated.</param>
/// <param name="columnType">The database type of the column.</param>
/// <param name="typeMapping">The relational type mapping to be used for the command parameter.</param>
/// <param name="read">Indicates whether a value must be read from the database for the column.</param>
/// <param name="write">Indicates whether a value must be written to the database for the column.</param>
/// <param name="key">Indicates whether the column part of a primary or alternate key.</param>
/// <param name="condition">Indicates whether the column is used in the <c>WHERE</c> clause when updating.</param>
/// <param name="sensitiveLoggingEnabled">Indicates whether potentially sensitive data (e.g. database values) can be logged.</param>
/// <param name="isNullable">A value indicating whether the value could be null.</param>
public ColumnModificationParameters(
string columnName,
object? originalValue,
object? value,
string? columnType,
RelationalTypeMapping? typeMapping,
string jsonPath,
bool read,
bool write,
bool key,
bool condition,
bool sensitiveLoggingEnabled,
bool? isNullable = null)
{
Column = null;
ColumnName = columnName;
OriginalValue = originalValue;
Value = value;
Property = null;
ColumnType = columnType;
TypeMapping = typeMapping;
JsonPath = jsonPath;
IsRead = read;
IsWrite = write;
IsKey = key;
IsCondition = condition;
SensitiveLoggingEnabled = sensitiveLoggingEnabled;
IsNullable = isNullable;

GenerateParameterName = null;
Entry = null;
}
}
5 changes: 5 additions & 0 deletions src/EFCore.Relational/Update/IColumnModification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public interface IColumnModification
/// </summary>
public object? Value { get; set; }

/// <summary>
/// In case of JSON column modification, the JSON path leading to the JSON element that needs to be updated.
/// </summary>
public string? JsonPath { get; }

/// <summary>
/// Adds a modification affecting the same database value.
/// </summary>
Expand Down
Loading