Skip to content

Commit

Permalink
Document that HasMaxLength(-1) means no maximum length (#30137)
Browse files Browse the repository at this point in the history
Continues #29627
  • Loading branch information
roji authored Jan 26, 2023
1 parent e5fbee3 commit fe091cc
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public interface IConventionPropertyBuilder : IConventionPropertyBaseBuilder
/// <summary>
/// Configures the maximum length of data that can be stored in this property.
/// </summary>
/// <param name="maxLength">The maximum length of data allowed in the property.</param>
/// <param name="maxLength">
/// The maximum length of data allowed in the property. A value of <c>-1</c> indicates that the property has no maximum length.
/// </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,
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore/Metadata/Builders/PropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public virtual PropertyBuilder IsRequired(bool required = true)
/// Configures the maximum length of data that can be stored in this property.
/// Maximum length can only be set on array properties (including <see cref="string" /> properties).
/// </summary>
/// <param name="maxLength">The maximum length of data allowed in the property.</param>
/// <param name="maxLength">
/// The maximum length of data allowed in the property. A value of <c>-1</c> indicates that the property has no maximum length.
/// </param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public virtual PropertyBuilder HasMaxLength(int maxLength)
{
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore/Metadata/Builders/PropertyBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public PropertyBuilder(IMutableProperty property)
/// Configures the maximum length of data that can be stored in this property.
/// Maximum length can only be set on array properties (including <see cref="string" /> properties).
/// </summary>
/// <param name="maxLength">The maximum length of data allowed in the property.</param>
/// <param name="maxLength">
/// The maximum length of data allowed in the property. A value of <c>-1</c> indicates that the property has no maximum length.
/// </param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public new virtual PropertyBuilder<TProperty> HasMaxLength(int maxLength)
=> (PropertyBuilder<TProperty>)base.HasMaxLength(maxLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public virtual TypeMappingConfigurationBuilder HasAnnotation(string annotation,
/// Configures the maximum length of data that can be stored in this property.
/// Maximum length can only be set on array properties (including <see cref="string" /> properties).
/// </summary>
/// <param name="maxLength">The maximum length of data allowed in the property.</param>
/// <param name="maxLength">
/// The maximum length of data allowed in the property. A value of <c>-1</c> indicates that the property has no maximum length.
/// </param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public virtual TypeMappingConfigurationBuilder HasMaxLength(int maxLength)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public TypeMappingConfigurationBuilder(PropertyConfiguration scalar)
/// Configures the maximum length of data that can be stored in this property.
/// Maximum length can only be set on array properties (including <see cref="string" /> properties).
/// </summary>
/// <param name="maxLength">The maximum length of data allowed in the property.</param>
/// <param name="maxLength">
/// The maximum length of data allowed in the property. A value of <c>-1</c> indicates that the property has no maximum length.
/// </param>
/// <returns>The same builder instance so that multiple configuration calls can be chained.</returns>
public new virtual TypeMappingConfigurationBuilder<TProperty> HasMaxLength(int maxLength)
=> (TypeMappingConfigurationBuilder<TProperty>)base.HasMaxLength(maxLength);
Expand Down
5 changes: 4 additions & 1 deletion src/EFCore/Metadata/IReadOnlyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ CoreTypeMapping GetTypeMapping()
/// Gets the maximum length of data that is allowed in this property. For example, if the property is a <see cref="string" />
/// then this is the maximum number of characters.
/// </summary>
/// <returns>The maximum length, or <see langword="null" /> if none is defined.</returns>
/// <returns>
/// The maximum length, <c>-1</c> if the property has no maximum length, or <see langword="null" /> if the maximum length hasn't been
/// set.
/// </returns>
int? GetMaxLength();

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore/Metadata/Internal/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ private static bool DefaultIsConcurrencyToken
/// </summary>
public virtual int? SetMaxLength(int? maxLength, ConfigurationSource configurationSource)
{
if (maxLength != null
&& maxLength < -1)
if (maxLength is < -1)
{
throw new ArgumentOutOfRangeException(nameof(maxLength));
}
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore/Metadata/Internal/PropertyConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public virtual void Apply(IMutableProperty property)
/// </summary>
public virtual void SetMaxLength(int? maxLength)
{
if (maxLength != null
&& maxLength < -1)
if (maxLength is < -1)
{
throw new ArgumentOutOfRangeException(nameof(maxLength));
}
Expand Down

0 comments on commit fe091cc

Please sign in to comment.