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

Rename Scalars to DefaultTypeMapping #25583

Merged
merged 1 commit into from
Aug 19, 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 @@ -352,7 +352,7 @@ private string CreateModelBuilder(
namespaces,
variables);

foreach (var typeConfiguration in model.GetScalarTypeConfigurations())
foreach (var typeConfiguration in model.GetTypeMappingConfigurations())
{
Create(typeConfiguration, parameters);
}
Expand Down Expand Up @@ -383,14 +383,14 @@ private string CreateModelBuilder(
}

private void Create(
IScalarTypeConfiguration typeConfiguration,
ITypeMappingConfiguration typeConfiguration,
CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
{
var variableName = _code.Identifier("type", parameters.ScopeVariables, capitalize: false);

var mainBuilder = parameters.MainBuilder;
mainBuilder
.Append("var ").Append(variableName).Append(" = ").Append(parameters.TargetName).AppendLine(".AddScalarTypeConfiguration(")
.Append("var ").Append(variableName).Append(" = ").Append(parameters.TargetName).AppendLine(".AddTypeMappingConfiguration(")
.IncrementIndent()
.Append(_code.Literal(typeConfiguration.ClrType));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore
/// <summary>
/// Relational database specific extension methods for <see cref="PropertiesConfigurationBuilder" />.
/// </summary>
public static class PropertiesConfigurationBuilderExtensions
public static class RelationalPropertiesConfigurationBuilderExtensions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I noticed this was missing Relational too

{
/// <summary>
/// Configures the data type of the column that the property maps to when targeting a relational database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Microsoft.EntityFrameworkCore
{
/// <summary>
/// Relational database specific extension methods for <see cref="ScalarConfigurationBuilder" />.
/// Relational database specific extension methods for <see cref="TypeMappingConfigurationBuilder" />.
/// </summary>
public static class ScalarConfigurationBuilderExtensions
public static class RelationalTypeMappingConfigurationBuilderExtensions
{
/// <summary>
/// Configures the data type of the column that the scalar maps to when targeting a relational database.
Expand All @@ -20,14 +20,14 @@ public static class ScalarConfigurationBuilderExtensions
/// <param name="scalarBuilder"> The builder for the scalar being configured. </param>
/// <param name="typeName"> The name of the data type of the column. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ScalarConfigurationBuilder HaveColumnType(
this ScalarConfigurationBuilder scalarBuilder,
public static TypeMappingConfigurationBuilder HasColumnType(
this TypeMappingConfigurationBuilder scalarBuilder,
string typeName)
{
Check.NotNull(scalarBuilder, nameof(scalarBuilder));
Check.NotEmpty(typeName, nameof(typeName));

scalarBuilder.HaveAnnotation(RelationalAnnotationNames.ColumnType, typeName);
scalarBuilder.HasAnnotation(RelationalAnnotationNames.ColumnType, typeName);

return scalarBuilder;
}
Expand All @@ -40,24 +40,24 @@ public static ScalarConfigurationBuilder HaveColumnType(
/// <param name="scalarBuilder"> The builder for the scalar being configured. </param>
/// <param name="typeName"> The name of the data type of the column. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static ScalarConfigurationBuilder<TScalar> HaveColumnType<TScalar>(
this ScalarConfigurationBuilder<TScalar> scalarBuilder,
public static TypeMappingConfigurationBuilder<TScalar> HasColumnType<TScalar>(
this TypeMappingConfigurationBuilder<TScalar> scalarBuilder,
string typeName)
=> (ScalarConfigurationBuilder<TScalar>)HaveColumnType((ScalarConfigurationBuilder)scalarBuilder, typeName);
=> (TypeMappingConfigurationBuilder<TScalar>)HasColumnType((TypeMappingConfigurationBuilder)scalarBuilder, typeName);

/// <summary>
/// Configures the scalar as capable of storing only fixed-length data, such as strings.
/// </summary>
/// <param name="scalarBuilder"> The builder for the scalar being configured. </param>
/// <param name="fixedLength"> A value indicating whether the scalar is constrained to fixed length values. </param>
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public static ScalarConfigurationBuilder AreFixedLength(
this ScalarConfigurationBuilder scalarBuilder,
public static TypeMappingConfigurationBuilder IsFixedLength(
this TypeMappingConfigurationBuilder scalarBuilder,
bool fixedLength = true)
{
Check.NotNull(scalarBuilder, nameof(scalarBuilder));

scalarBuilder.HaveAnnotation(RelationalAnnotationNames.IsFixedLength, fixedLength);
scalarBuilder.HasAnnotation(RelationalAnnotationNames.IsFixedLength, fixedLength);

return scalarBuilder;
}
Expand All @@ -69,9 +69,9 @@ public static ScalarConfigurationBuilder AreFixedLength(
/// <param name="scalarBuilder"> The builder for the scalar being configured. </param>
/// <param name="fixedLength"> A value indicating whether the scalar is constrained to fixed length values. </param>
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public static ScalarConfigurationBuilder<TScalar> AreFixedLength<TScalar>(
this ScalarConfigurationBuilder<TScalar> scalarBuilder,
public static TypeMappingConfigurationBuilder<TScalar> IsFixedLength<TScalar>(
this TypeMappingConfigurationBuilder<TScalar> scalarBuilder,
bool fixedLength = true)
=> (ScalarConfigurationBuilder<TScalar>)AreFixedLength((ScalarConfigurationBuilder)scalarBuilder, fixedLength);
=> (TypeMappingConfigurationBuilder<TScalar>)IsFixedLength((TypeMappingConfigurationBuilder)scalarBuilder, fixedLength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
public override CoreTypeMapping? FindMapping(Type type, IModel model)
{
type = type.UnwrapNullableType();
var typeConfiguration = model.FindScalarTypeConfiguration(type);
var typeConfiguration = model.FindTypeMappingConfiguration(type);
RelationalTypeMappingInfo mappingInfo;
Type? providerClrType = null;
ValueConverter? customConverter = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public virtual void Generate(IIndex index, CSharpRuntimeAnnotationCodeGeneratorP
}

/// <inheritdoc />
public virtual void Generate(IScalarTypeConfiguration typeConfiguration, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
public virtual void Generate(ITypeMappingConfiguration typeConfiguration, CSharpRuntimeAnnotationCodeGeneratorParameters parameters)
{
if (!parameters.IsRuntime)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public interface ICSharpRuntimeAnnotationCodeGenerator
/// </summary>
/// <param name="typeConfiguration"> The scalar type configuration to which the annotations are applied. </param>
/// <param name="parameters"> Additional parameters used during code generation. </param>
void Generate(IScalarTypeConfiguration typeConfiguration, CSharpRuntimeAnnotationCodeGeneratorParameters parameters);
void Generate(ITypeMappingConfiguration typeConfiguration, CSharpRuntimeAnnotationCodeGeneratorParameters parameters);
}
}
26 changes: 13 additions & 13 deletions src/EFCore/Metadata/Builders/PropertiesConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public PropertiesConfigurationBuilder(PropertyConfiguration property)
{
Check.NotNull(property, nameof(property));

Property = property;
Configuration = property;
}

/// <summary>
Expand All @@ -43,7 +43,7 @@ public PropertiesConfigurationBuilder(PropertyConfiguration property)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
protected virtual PropertyConfiguration Property { get; }
protected virtual PropertyConfiguration Configuration { get; }

/// <summary>
/// Adds or updates an annotation on the property.
Expand All @@ -55,7 +55,7 @@ public virtual PropertiesConfigurationBuilder HaveAnnotation(string annotation,
{
Check.NotEmpty(annotation, nameof(annotation));

Property[annotation] = value;
Configuration[annotation] = value;

return this;
}
Expand All @@ -68,7 +68,7 @@ public virtual PropertiesConfigurationBuilder HaveAnnotation(string annotation,
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual PropertiesConfigurationBuilder HaveMaxLength(int maxLength)
{
Property.SetMaxLength(maxLength);
Configuration.SetMaxLength(maxLength);

return this;
}
Expand All @@ -81,8 +81,8 @@ public virtual PropertiesConfigurationBuilder HaveMaxLength(int maxLength)
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual PropertiesConfigurationBuilder HavePrecision(int precision, int scale)
{
Property.SetPrecision(precision);
Property.SetScale(scale);
Configuration.SetPrecision(precision);
Configuration.SetScale(scale);

return this;
}
Expand All @@ -96,7 +96,7 @@ public virtual PropertiesConfigurationBuilder HavePrecision(int precision, int s
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual PropertiesConfigurationBuilder HavePrecision(int precision)
{
Property.SetPrecision(precision);
Configuration.SetPrecision(precision);

return this;
}
Expand All @@ -109,7 +109,7 @@ public virtual PropertiesConfigurationBuilder HavePrecision(int precision)
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual PropertiesConfigurationBuilder AreUnicode(bool unicode = true)
{
Property.SetIsUnicode(unicode);
Configuration.SetIsUnicode(unicode);

return this;
}
Expand All @@ -135,11 +135,11 @@ public virtual PropertiesConfigurationBuilder HaveConversion(Type conversionType

if (typeof(ValueConverter).IsAssignableFrom(conversionType))
{
Property.SetValueConverter(conversionType);
Configuration.SetValueConverter(conversionType);
}
else
{
Property.SetProviderClrType(conversionType);
Configuration.SetProviderClrType(conversionType);
}

return this;
Expand Down Expand Up @@ -169,14 +169,14 @@ public virtual PropertiesConfigurationBuilder HaveConversion(Type conversionType

if (typeof(ValueConverter).IsAssignableFrom(conversionType))
{
Property.SetValueConverter(conversionType);
Configuration.SetValueConverter(conversionType);
}
else
{
Property.SetProviderClrType(conversionType);
Configuration.SetProviderClrType(conversionType);
}

Property.SetValueComparer(comparerType);
Configuration.SetValueComparer(comparerType);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Builders
/// and it is not designed to be directly constructed in your application code.
/// </para>
/// </summary>
public class ScalarConfigurationBuilder
public class TypeMappingConfigurationBuilder
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -27,11 +27,11 @@ public class ScalarConfigurationBuilder
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
public ScalarConfigurationBuilder(PropertyConfiguration scalar)
public TypeMappingConfigurationBuilder(PropertyConfiguration scalar)
{
Check.NotNull(scalar, nameof(scalar));

Scalar = scalar;
Configuration = scalar;
}

/// <summary>
Expand All @@ -41,19 +41,19 @@ public ScalarConfigurationBuilder(PropertyConfiguration scalar)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
protected virtual PropertyConfiguration Scalar { get; }
protected virtual PropertyConfiguration Configuration { get; }

/// <summary>
/// Adds or updates an annotation on the property.
/// </summary>
/// <param name="annotation"> The key of the annotation to be added or updated. </param>
/// <param name="value"> The value to be stored in the annotation. </param>
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual ScalarConfigurationBuilder HaveAnnotation(string annotation, object value)
public virtual TypeMappingConfigurationBuilder HasAnnotation(string annotation, object value)
{
Check.NotEmpty(annotation, nameof(annotation));

Scalar[annotation] = value;
Configuration[annotation] = value;

return this;
}
Expand All @@ -64,9 +64,9 @@ public virtual ScalarConfigurationBuilder HaveAnnotation(string annotation, obje
/// </summary>
/// <param name="maxLength"> The maximum length of data allowed in the property. </param>
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual ScalarConfigurationBuilder HaveMaxLength(int maxLength)
public virtual TypeMappingConfigurationBuilder HasMaxLength(int maxLength)
{
Scalar.SetMaxLength(maxLength);
Configuration.SetMaxLength(maxLength);

return this;
}
Expand All @@ -77,10 +77,10 @@ public virtual ScalarConfigurationBuilder HaveMaxLength(int maxLength)
/// <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 ScalarConfigurationBuilder HavePrecision(int precision, int scale)
public virtual TypeMappingConfigurationBuilder HasPrecision(int precision, int scale)
{
Scalar.SetPrecision(precision);
Scalar.SetScale(scale);
Configuration.SetPrecision(precision);
Configuration.SetScale(scale);

return this;
}
Expand All @@ -92,9 +92,9 @@ public virtual ScalarConfigurationBuilder HavePrecision(int precision, int scale
/// </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 ScalarConfigurationBuilder HavePrecision(int precision)
public virtual TypeMappingConfigurationBuilder HasPrecision(int precision)
{
Scalar.SetPrecision(precision);
Configuration.SetPrecision(precision);

return this;
}
Expand All @@ -105,9 +105,9 @@ public virtual ScalarConfigurationBuilder HavePrecision(int precision)
/// </summary>
/// <param name="unicode"> A value indicating whether the property can contain unicode characters. </param>
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual ScalarConfigurationBuilder AreUnicode(bool unicode = true)
public virtual TypeMappingConfigurationBuilder IsUnicode(bool unicode = true)
{
Scalar.SetIsUnicode(unicode);
Configuration.SetIsUnicode(unicode);

return this;
}
Expand All @@ -118,26 +118,26 @@ public virtual ScalarConfigurationBuilder AreUnicode(bool unicode = true)
/// </summary>
/// <typeparam name="TConversion"> The type to convert to and from or a type that derives from <see cref="ValueConverter"/>. </typeparam>
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual ScalarConfigurationBuilder HaveConversion<TConversion>()
=> HaveConversion(typeof(TConversion));
public virtual TypeMappingConfigurationBuilder HasConversion<TConversion>()
=> HasConversion(typeof(TConversion));

/// <summary>
/// Configures the property so that the property value is converted before
/// writing to the database and converted back when reading from the database.
/// </summary>
/// <param name="conversionType"> The type to convert to and from or a type that derives from <see cref="ValueConverter"/>. </param>
/// <returns> The same builder instance so that multiple configuration calls can be chained. </returns>
public virtual ScalarConfigurationBuilder HaveConversion(Type conversionType)
public virtual TypeMappingConfigurationBuilder HasConversion(Type conversionType)
{
Check.NotNull(conversionType, nameof(conversionType));

if (typeof(ValueConverter).IsAssignableFrom(conversionType))
{
Scalar.SetValueConverter(conversionType);
Configuration.SetValueConverter(conversionType);
}
else
{
Scalar.SetProviderClrType(conversionType);
Configuration.SetProviderClrType(conversionType);
}

return this;
Expand Down
Loading