Skip to content
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 @@ -71,4 +71,31 @@ public static ComplexCollectionBuilder<TComplex> HasJsonPropertyName<TComplex>(
string? name)
where TComplex : notnull
=> (ComplexCollectionBuilder<TComplex>)HasJsonPropertyName((ComplexCollectionBuilder)complexCollectionBuilder, name);

/// <summary>
/// Configures the column type for the JSON column that stores the complex collection.
/// </summary>
/// <param name="complexCollectionBuilder">The builder for the complex collection being configured.</param>
/// <param name="columnType">The database type for the column, or <see langword="null" /> to use the database default.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static ComplexCollectionBuilder HasColumnType(
this ComplexCollectionBuilder complexCollectionBuilder,
string? columnType)
{
complexCollectionBuilder.Metadata.ComplexType.SetContainerColumnType(columnType);

return complexCollectionBuilder;
}

/// <summary>
/// Configures the column type for the JSON column that stores the complex collection.
/// </summary>
/// <param name="complexCollectionBuilder">The builder for the complex collection being configured.</param>
/// <param name="columnType">The database type for the column, or <see langword="null" /> to use the database default.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static ComplexCollectionBuilder<TComplex> HasColumnType<TComplex>(
this ComplexCollectionBuilder<TComplex> complexCollectionBuilder,
string? columnType)
where TComplex : notnull
=> (ComplexCollectionBuilder<TComplex>)HasColumnType((ComplexCollectionBuilder)complexCollectionBuilder, columnType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,31 @@ public static ComplexPropertyBuilder<TComplex> HasJsonPropertyName<TComplex>(
string? name)
where TComplex : notnull
=> (ComplexPropertyBuilder<TComplex>)HasJsonPropertyName((ComplexPropertyBuilder)complexPropertyBuilder, name);

/// <summary>
/// Configures the column type for the JSON column that stores the complex property.
/// </summary>
/// <param name="complexPropertyBuilder">The builder for the complex property being configured.</param>
/// <param name="columnType">The database type for the column, or <see langword="null" /> to use the database default.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static ComplexPropertyBuilder HasColumnType(
this ComplexPropertyBuilder complexPropertyBuilder,
string? columnType)
{
complexPropertyBuilder.Metadata.ComplexType.SetContainerColumnType(columnType);

return complexPropertyBuilder;
}

/// <summary>
/// Configures the column type for the JSON column that stores the complex property.
/// </summary>
/// <param name="complexPropertyBuilder">The builder for the complex property being configured.</param>
/// <param name="columnType">The database type for the column, or <see langword="null" /> to use the database default.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static ComplexPropertyBuilder<TComplex> HasColumnType<TComplex>(
this ComplexPropertyBuilder<TComplex> complexPropertyBuilder,
string? columnType)
where TComplex : notnull
=> (ComplexPropertyBuilder<TComplex>)HasColumnType((ComplexPropertyBuilder)complexPropertyBuilder, columnType);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1564,87 +1564,6 @@ public static void SetMappingStrategy(this IMutableEntityType entityType, string
public static bool IsMappedToJson(this IReadOnlyEntityType entityType)
=> !string.IsNullOrEmpty(entityType.GetContainerColumnName());

/// <summary>
/// Sets the name of the container column to which the entity type is mapped.
/// </summary>
/// <param name="entityType">The entity type to set the container column name for.</param>
/// <param name="columnName">The name to set.</param>
public static void SetContainerColumnName(this IMutableEntityType entityType, string? columnName)
=> entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.ContainerColumnName, columnName);

/// <summary>
/// Sets the name of the container column to which the entity type is mapped.
/// </summary>
/// <param name="entityType">The entity type to set the container column name for.</param>
/// <param name="columnName">The name to set.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetContainerColumnName(
this IConventionEntityType entityType,
string? columnName,
bool fromDataAnnotation = false)
=> (string?)entityType.SetAnnotation(RelationalAnnotationNames.ContainerColumnName, columnName, fromDataAnnotation)?.Value;

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the container column name.
/// </summary>
/// <param name="entityType">The entity type to set the container column name for.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the container column name.</returns>
public static ConfigurationSource? GetContainerColumnNameConfigurationSource(this IConventionEntityType entityType)
=> entityType.FindAnnotation(RelationalAnnotationNames.ContainerColumnName)
?.GetConfigurationSource();

/// <summary>
/// Gets the container column name to which the entity type is mapped.
/// </summary>
/// <param name="entityType">The entity type to get the container column name for.</param>
/// <returns>The container column name to which the entity type is mapped.</returns>
public static string? GetContainerColumnName(this IReadOnlyEntityType entityType)
{
var containerColumnName = entityType.FindAnnotation(RelationalAnnotationNames.ContainerColumnName);
return containerColumnName == null
? entityType.FindOwnership()?.PrincipalEntityType.GetContainerColumnName()
: (string?)containerColumnName.Value;
}

/// <summary>
/// Sets the column type to use for the container column to which the entity type is mapped.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <param name="columnType">The database column type.</param>
public static void SetContainerColumnType(this IMutableEntityType entityType, string? columnType)
=> entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.ContainerColumnType, columnType);

/// <summary>
/// Sets the column type to use for the container column to which the entity type is mapped.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <param name="columnType">The database column type.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetContainerColumnType(
this IConventionEntityType entityType,
string? columnType,
bool fromDataAnnotation = false)
=> (string?)entityType.SetAnnotation(RelationalAnnotationNames.ContainerColumnType, columnType, fromDataAnnotation)?.Value;

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the container column type.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <returns>The <see cref="ConfigurationSource" />.</returns>
public static ConfigurationSource? GetContainerColumnTypeConfigurationSource(this IConventionEntityType entityType)
=> entityType.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)
?.GetConfigurationSource();

/// <summary>
/// Gets the column type to use for the container column to which the entity type is mapped.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <returns>The database column type.</returns>
public static string? GetContainerColumnType(this IReadOnlyEntityType entityType)
=> entityType.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)?.Value as string;

/// <summary>
/// Sets the type mapping for the container column to which the entity type is mapped.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2047,11 +2047,14 @@ private static TValue ThrowReadValueException<TValue>(
/// <param name="property">The property.</param>
/// <returns>
/// The value for the JSON property used to store the value of this entity property.
/// <see langword="null" /> is returned for key properties and for properties of entities that are not mapped to a JSON column.
/// By default <see langword="null" /> is returned for key properties and for properties that
/// are not mapped to JSON.
/// </returns>
public static string? GetJsonPropertyName(this IReadOnlyProperty property)
=> (string?)property.FindAnnotation(RelationalAnnotationNames.JsonPropertyName)?.Value
?? (property.IsKey() || !property.DeclaringType.IsMappedToJson() ? null : property.Name);
?? (property.IsKey() || !property.DeclaringType.IsMappedToJson()
? null
: property == property.DeclaringType.FindDiscriminatorProperty() ? "$type" : property.Name);

/// <summary>
/// Sets the value of JSON property name used for the given property of an entity mapped to a JSON column.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ReSharper disable once CheckNamespace

using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore;

Expand Down Expand Up @@ -370,20 +371,87 @@ public static bool IsMappedToJson(this IReadOnlyTypeBase typeBase)
/// <param name="typeBase">The type to get the container column name for.</param>
/// <returns>The container column name to which the type is mapped.</returns>
public static string? GetContainerColumnName(this IReadOnlyTypeBase typeBase)
=> typeBase is IReadOnlyEntityType entityType
? entityType.GetContainerColumnName()
: ((IReadOnlyComplexType)typeBase).GetContainerColumnName();
{
var containerColumnName = typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnName);
return containerColumnName != null
? (string?)containerColumnName.Value
: typeBase is IReadOnlyEntityType entityType
? entityType.FindOwnership()?.PrincipalEntityType.GetContainerColumnName()
: ((IReadOnlyComplexType)typeBase).ComplexProperty.DeclaringType.GetContainerColumnName();
}

/// <summary>
/// Sets the name of the container column to which the type is mapped.
/// </summary>
/// <param name="typeBase">The type to set the container column name for.</param>
/// <param name="columnName">The name to set.</param>
public static void SetContainerColumnName(this IMutableTypeBase typeBase, string? columnName)
=> typeBase.SetOrRemoveAnnotation(RelationalAnnotationNames.ContainerColumnName, columnName);

/// <summary>
/// Sets the name of the container column to which the type is mapped.
/// </summary>
/// <param name="typeBase">The type to set the container column name for.</param>
/// <param name="columnName">The name to set.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetContainerColumnName(
this IConventionTypeBase typeBase,
string? columnName,
bool fromDataAnnotation = false)
=> (string?)typeBase.SetAnnotation(RelationalAnnotationNames.ContainerColumnName, columnName, fromDataAnnotation)?.Value;

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the container column name.
/// </summary>
/// <param name="typeBase">The type to get the container column name configuration source for.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the container column name.</returns>
public static ConfigurationSource? GetContainerColumnNameConfigurationSource(this IConventionTypeBase typeBase)
=> typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnName)
?.GetConfigurationSource();

/// <summary>
/// Gets the column type to use for the container column to which the type is mapped.
/// </summary>
/// <param name="typeBase">The type.</param>
/// <returns>The database column type.</returns>
public static string? GetContainerColumnType(this IReadOnlyTypeBase typeBase)
=> typeBase is IReadOnlyEntityType entityType
? entityType.GetContainerColumnType()
: null;
=> typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)?.Value is string columnName
? columnName
: typeBase is IReadOnlyEntityType entityType
? entityType.FindOwnership()?.PrincipalEntityType.GetContainerColumnType()
: ((IReadOnlyComplexType)typeBase).ComplexProperty.DeclaringType.GetContainerColumnType();

/// <summary>
/// Sets the type of the container column to which the type is mapped.
/// </summary>
/// <param name="typeBase">The type to set the container column type for.</param>
/// <param name="columnType">The type to set.</param>
public static void SetContainerColumnType(this IMutableTypeBase typeBase, string? columnType)
=> typeBase.SetOrRemoveAnnotation(RelationalAnnotationNames.ContainerColumnType, columnType);

/// <summary>
/// Sets the type of the container column to which the type is mapped.
/// </summary>
/// <param name="typeBase">The type to set the container column type for.</param>
/// <param name="columnType">The type to set.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetContainerColumnType(
this IConventionTypeBase typeBase,
string? columnType,
bool fromDataAnnotation = false)
=> (string?)typeBase.SetAnnotation(RelationalAnnotationNames.ContainerColumnType, columnType, fromDataAnnotation)?.Value;

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the container column type.
/// </summary>
/// <param name="typeBase">The type to get the container column type configuration source for.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the container column type.</returns>
public static ConfigurationSource? GetContainerColumnTypeConfigurationSource(this IConventionTypeBase typeBase)
=> typeBase.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)
?.GetConfigurationSource();

/// <summary>
/// Gets the value of JSON property name used for the given entity mapped to a JSON column.
/// </summary>
Expand Down
Loading