Skip to content

Commit

Permalink
Updated based on review.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 1, 2023
1 parent 2f2fa8b commit 0197f5f
Show file tree
Hide file tree
Showing 47 changed files with 3,466 additions and 568 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class RelationalElementTypeBuilderExtensions
/// <param name="elementTypeBuilder">The builder for the elements being configured.</param>
/// <param name="typeName">The name of the data type of the elements.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static ElementTypeBuilder ElementsHaveStoreType(
public static ElementTypeBuilder HasStoreType(
this ElementTypeBuilder elementTypeBuilder,
string? typeName)
{
Expand All @@ -41,7 +41,7 @@ public static ElementTypeBuilder ElementsHaveStoreType(
/// <param name="typeName">The name of the data type of the elements.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The same builder instance if the configuration was applied, <see langword="null" /> otherwise.</returns>
public static IConventionElementTypeBuilder? ElementsHaveStoreType(
public static IConventionElementTypeBuilder? HasStoreType(
this IConventionElementTypeBuilder elementTypeBuilder,
string? typeName,
bool fromDataAnnotation = false)
Expand Down Expand Up @@ -80,7 +80,7 @@ public static bool CanSetStoreType(
/// <param name="elementTypeBuilder">The builder for the elements being configured.</param>
/// <param name="fixedLength">A value indicating whether the elements are constrained to fixed length values.</param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public static ElementTypeBuilder ElementsAreFixedLength(
public static ElementTypeBuilder IsFixedLength(
this ElementTypeBuilder elementTypeBuilder,
bool fixedLength = true)
{
Expand All @@ -99,7 +99,7 @@ public static ElementTypeBuilder ElementsAreFixedLength(
/// <param name="fixedLength">A value indicating whether the elements are constrained to fixed length values.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns> The same builder instance if the configuration was applied, <see langword="null" /> otherwise.</returns>
public static IConventionElementTypeBuilder? ElementsAreFixedLength(
public static IConventionElementTypeBuilder? IsFixedLength(
this IConventionElementTypeBuilder elementTypeBuilder,
bool? fixedLength,
bool fromDataAnnotation = false)
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Storage/RelationalTypeMappingInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public RelationalTypeMappingInfo(
_coreTypeMappingInfo = new TypeMappingInfo(elementType, fallbackUnicode, fallbackSize, fallbackPrecision, fallbackScale);

fallbackFixedLength ??= elementType.IsFixedLength();
storeTypeName ??= elementType.GetStoreType();
storeTypeName ??= (string?)elementType[RelationalAnnotationNames.StoreType];

var customConverter = elementType.GetValueConverter();
var mappingHints = customConverter?.MappingHints;
Expand Down
20 changes: 10 additions & 10 deletions src/EFCore/ChangeTracking/Internal/ValueComparerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ public static class ValueComparerExtensions
/// 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 ValueComparer? ToNullableComparer(this ValueComparer? valueComparer, IReadOnlyProperty property)
public static ValueComparer? ToNullableComparer(this ValueComparer? valueComparer, Type clrType)
{
if (valueComparer == null
|| !property.ClrType.IsNullableValueType()
|| !clrType.IsNullableValueType()
|| valueComparer.Type.IsNullableValueType())
{
return valueComparer;
}

var newEqualsParam1 = Expression.Parameter(property.ClrType, "v1");
var newEqualsParam2 = Expression.Parameter(property.ClrType, "v2");
var newHashCodeParam = Expression.Parameter(property.ClrType, "v");
var newSnapshotParam = Expression.Parameter(property.ClrType, "v");
var hasValueMethod = property.ClrType.GetMethod("get_HasValue")!;
var newEqualsParam1 = Expression.Parameter(clrType, "v1");
var newEqualsParam2 = Expression.Parameter(clrType, "v2");
var newHashCodeParam = Expression.Parameter(clrType, "v");
var newSnapshotParam = Expression.Parameter(clrType, "v");
var hasValueMethod = clrType.GetMethod("get_HasValue")!;
var v1HasValue = Expression.Parameter(typeof(bool), "v1HasValue");
var v2HasValue = Expression.Parameter(typeof(bool), "v2HasValue");

return (ValueComparer)Activator.CreateInstance(
typeof(ValueComparer<>).MakeGenericType(property.ClrType),
typeof(ValueComparer<>).MakeGenericType(clrType),
Expression.Lambda(
Expression.Block(
typeof(bool),
Expand Down Expand Up @@ -66,8 +66,8 @@ public static class ValueComparerExtensions
Expression.Call(newSnapshotParam, hasValueMethod),
Expression.Convert(
valueComparer.ExtractSnapshotBody(
Expression.Convert(newSnapshotParam, valueComparer.Type)), property.ClrType),
Expression.Default(property.ClrType)),
Expression.Convert(newSnapshotParam, valueComparer.Type)), clrType),
Expression.Default(clrType)),
newSnapshotParam))!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,6 @@ public virtual ComplexTypePrimitiveCollectionBuilder HasSentinel(object? sentine
return this;
}

/// <summary>
/// Configures the precision and scale of the property.
/// </summary>
/// <param name="precision">The precision of the property.</param>
/// <param name="scale">The scale of the property.</param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public virtual ComplexTypePrimitiveCollectionBuilder HasPrecision(int precision, int scale)
{
Builder.HasPrecision(precision, ConfigurationSource.Explicit);
Builder.HasScale(scale, ConfigurationSource.Explicit);

return this;
}

/// <summary>
/// Configures the precision of the property.
/// </summary>
/// <param name="precision">The precision of the property.</param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public virtual ComplexTypePrimitiveCollectionBuilder HasPrecision(int precision)
{
Builder.HasPrecision(precision, ConfigurationSource.Explicit);

return this;
}

/// <summary>
/// Configures whether the property as capable of persisting unicode characters.
/// Can only be set on <see cref="string" /> properties.
Expand All @@ -148,23 +122,6 @@ public virtual ComplexTypePrimitiveCollectionBuilder IsUnicode(bool unicode = tr
return this;
}

/// <summary>
/// Configures the property as <see cref="ValueGeneratedOnAddOrUpdate" /> and
/// <see cref="IsConcurrencyToken" />.
/// </summary>
/// <remarks>
/// Database providers can choose to interpret this in different way, but it is commonly used
/// to indicate some form of automatic row-versioning as used for optimistic concurrency detection.
/// </remarks>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public virtual ComplexTypePrimitiveCollectionBuilder IsRowVersion()
{
Builder.ValueGenerated(ValueGenerated.OnAddOrUpdate, ConfigurationSource.Explicit);
Builder.IsConcurrencyToken(true, ConfigurationSource.Explicit);

return this;
}

/// <summary>
/// Configures the <see cref="ValueGenerator" /> that will generate values for this property.
/// </summary>
Expand Down Expand Up @@ -433,7 +390,7 @@ public virtual ComplexTypePrimitiveCollectionBuilder HasField(string fieldName)
}

/// <summary>
/// Configures the type of primitive value stored by the collection.
/// Configures this property as a collection containing elements of a primitive type.
/// </summary>
/// <returns>A builder to configure the collection element type.</returns>
public virtual ElementTypeBuilder ElementType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,6 @@ public ComplexTypePrimitiveCollectionBuilder(IMutableProperty property)
public new virtual ComplexTypePrimitiveCollectionBuilder<TProperty> HasSentinel(object? sentinel)
=> (ComplexTypePrimitiveCollectionBuilder<TProperty>)base.HasSentinel(sentinel);

/// <summary>
/// Configures the precision and scale of the property.
/// </summary>
/// <param name="precision">The precision of the property.</param>
/// <param name="scale">The scale of the property.</param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public new virtual ComplexTypePrimitiveCollectionBuilder<TProperty> HasPrecision(int precision, int scale)
=> (ComplexTypePrimitiveCollectionBuilder<TProperty>)base.HasPrecision(precision, scale);

/// <summary>
/// Configures the precision of the property.
/// </summary>
/// <param name="precision">The precision of the property.</param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public new virtual ComplexTypePrimitiveCollectionBuilder<TProperty> HasPrecision(int precision)
=> (ComplexTypePrimitiveCollectionBuilder<TProperty>)base.HasPrecision(precision);

/// <summary>
/// Configures the property as capable of persisting unicode characters.
/// Can only be set on <see cref="string" /> properties.
Expand All @@ -99,18 +82,6 @@ public ComplexTypePrimitiveCollectionBuilder(IMutableProperty property)
public new virtual ComplexTypePrimitiveCollectionBuilder<TProperty> IsUnicode(bool unicode = true)
=> (ComplexTypePrimitiveCollectionBuilder<TProperty>)base.IsUnicode(unicode);

/// <summary>
/// Configures the property as <see cref="ValueGeneratedOnAddOrUpdate" /> and
/// <see cref="IsConcurrencyToken" />.
/// </summary>
/// <remarks>
/// Database providers can choose to interpret this in different way, but it is commonly used
/// to indicate some form of automatic row-versioning as used for optimistic concurrency detection.
/// </remarks>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public new virtual ComplexTypePrimitiveCollectionBuilder<TProperty> IsRowVersion()
=> (ComplexTypePrimitiveCollectionBuilder<TProperty>)base.IsRowVersion();

/// <summary>
/// Configures the <see cref="ValueGenerator" /> that will generate values for this property.
/// </summary>
Expand Down
23 changes: 0 additions & 23 deletions src/EFCore/Metadata/Builders/ComplexTypePropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,29 +432,6 @@ public virtual ComplexTypePropertyBuilder HasField(string fieldName)
return this;
}

/// <summary>
/// Configures the type of primitive value stored by the collection.
/// </summary>
/// <returns>A builder to configure the collection element type.</returns>
public virtual ElementTypeBuilder ElementType()
{
Builder.HasElementType(ConfigurationSource.Explicit);

return new ElementTypeBuilder((IMutableElementType)Builder.Metadata.GetElementType()!);
}

/// <summary>
/// Configures this property as a collection containing elements of a primitive type.
/// </summary>
/// <param name="builderAction">An action that performs configuration of the collection element type.</param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public virtual ComplexTypePropertyBuilder ElementType(Action<ElementTypeBuilder> builderAction)
{
builderAction(ElementType());

return this;
}

/// <summary>
/// Sets the <see cref="PropertyAccessMode" /> to use for this property.
/// </summary>
Expand Down
8 changes: 0 additions & 8 deletions src/EFCore/Metadata/Builders/ComplexTypePropertyBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,6 @@ public ComplexTypePropertyBuilder(IMutableProperty property)
public new virtual ComplexTypePropertyBuilder<TProperty> HasField(string fieldName)
=> (ComplexTypePropertyBuilder<TProperty>)base.HasField(fieldName);

/// <summary>
/// Configures this property as a collection containing elements of a primitive type.
/// </summary>
/// <param name="builderAction">An action that performs configuration of the collection element type.</param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public new virtual ComplexTypePropertyBuilder<TProperty> ElementType(Action<ElementTypeBuilder> builderAction)
=> (ComplexTypePropertyBuilder<TProperty>)base.ElementType(builderAction);

/// <summary>
/// Sets the <see cref="PropertyAccessMode" /> to use for this property.
/// </summary>
Expand Down
Loading

0 comments on commit 0197f5f

Please sign in to comment.