Skip to content

Commit

Permalink
API review changes
Browse files Browse the repository at this point in the history
Part of #20409

- Use Field instead of FieldInfo in model building
- Change entityTypeName for `IDbSetCache.GetOrAddSet` and similar
- Rename CreateKeyValueReadExpression to CreateKeyValuesExpression
- Make IsQueryableType real internal
- Rename IndexedProperty to IndexerProperty and related
- Seal ExpressionEqualityComparer
- Change ReplacingExpressionVisitor to use `IReadOnlyList<Expression>`
- Use `ETag` instead of `Etag`
- Remove `GetViewOrTableColumnMappings`
- Rename IColumnBase.Type to StoreType
  • Loading branch information
ajcvickers committed Apr 18, 2020
1 parent 0471f9b commit 5d85022
Show file tree
Hide file tree
Showing 43 changed files with 144 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public static bool CanSetPartitionKey(
/// </summary>
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder UseEtagConcurrency([NotNull] this EntityTypeBuilder entityTypeBuilder)
public static EntityTypeBuilder UseETagConcurrency([NotNull] this EntityTypeBuilder entityTypeBuilder)
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));

Expand All @@ -276,11 +276,11 @@ public static EntityTypeBuilder UseEtagConcurrency([NotNull] this EntityTypeBuil
/// </summary>
/// <param name="entityTypeBuilder"> The builder for the entity type being configured. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static EntityTypeBuilder<TEntity> UseEtagConcurrency<TEntity>([NotNull] this EntityTypeBuilder<TEntity> entityTypeBuilder)
public static EntityTypeBuilder<TEntity> UseETagConcurrency<TEntity>([NotNull] this EntityTypeBuilder<TEntity> entityTypeBuilder)
where TEntity : class
{
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
UseEtagConcurrency((EntityTypeBuilder)entityTypeBuilder);
UseETagConcurrency((EntityTypeBuilder)entityTypeBuilder);
return entityTypeBuilder;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static bool CanSetJsonProperty(
/// </summary>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder IsEtagConcurrency([NotNull] this PropertyBuilder propertyBuilder)
public static PropertyBuilder IsETagConcurrency([NotNull] this PropertyBuilder propertyBuilder)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
propertyBuilder
Expand All @@ -109,8 +109,8 @@ public static PropertyBuilder IsEtagConcurrency([NotNull] this PropertyBuilder p
/// <typeparam name="TProperty"> The type of the property being configured. </typeparam>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder<TProperty> IsEtagConcurrency<TProperty>(
public static PropertyBuilder<TProperty> IsETagConcurrency<TProperty>(
[NotNull] this PropertyBuilder<TProperty> propertyBuilder)
=> (PropertyBuilder<TProperty>)IsEtagConcurrency((PropertyBuilder)propertyBuilder);
=> (PropertyBuilder<TProperty>)IsETagConcurrency((PropertyBuilder)propertyBuilder);
}
}
6 changes: 3 additions & 3 deletions src/EFCore.Cosmos/Internal/CosmosModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void Validate(IModel model, IDiagnosticsLogger<DbLoggerCategory.
base.Validate(model, logger);

ValidateSharedContainerCompatibility(model, logger);
ValidateOnlyEtagConcurrencyToken(model, logger);
ValidateOnlyETagConcurrencyToken(model, logger);
}

/// <summary>
Expand Down Expand Up @@ -181,7 +181,7 @@ protected virtual void ValidateSharedContainerCompatibility(
/// 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>
protected virtual void ValidateOnlyEtagConcurrencyToken(
protected virtual void ValidateOnlyETagConcurrencyToken(
[NotNull] IModel model,
[NotNull] IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
Expand All @@ -195,7 +195,7 @@ protected virtual void ValidateOnlyEtagConcurrencyToken(
if (storeName != "_etag")
{
throw new InvalidOperationException(
CosmosStrings.NonEtagConcurrencyToken(entityType.DisplayName(), storeName));
CosmosStrings.NonETagConcurrencyToken(entityType.DisplayName(), storeName));
}

var etagType = property.GetTypeMapping().Converter?.ProviderClrType ?? property.ClrType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public static class CosmosAnnotationNames
/// 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 const string ETagName = Prefix + "EtagName";
public const string ETagName = Prefix + "ETagName";
}
}
6 changes: 3 additions & 3 deletions src/EFCore.Cosmos/Properties/CosmosStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 29 additions & 29 deletions src/EFCore.Cosmos/Properties/CosmosStrings.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -132,8 +132,8 @@
<data name="NoDiscriminatorValue" xml:space="preserve">
<value>The entity type '{entityType}' is sharing the container '{container}' with other types, but does not have a discriminator value configured.</value>
</data>
<data name="NonEtagConcurrencyToken" xml:space="preserve">
<value>The entity type '{entityType}' has property '{property}' as its concurrency token, but only '_etag' is supported. Consider using 'EntityTypeBuilder.UseEtagConcurrency'.</value>
<data name="NonETagConcurrencyToken" xml:space="preserve">
<value>The entity type '{entityType}' has property '{property}' as its concurrency token, but only '_etag' is supported. Consider using 'EntityTypeBuilder.UseETagConcurrency'.</value>
</data>
<data name="NoPartitionKey" xml:space="preserve">
<value>The entity type '{entityType}' does not have a partition key set, but it is mapped to the container '{container}' shared by entity types with partition keys.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,12 @@ private Expression TryExpand(Expression source, MemberIdentity member)
.Select(p => p.ClrType)
.Any(t => t.IsNullableType());

var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
var outerKey = entityShaperExpression.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValueReadExpression(
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down Expand Up @@ -1147,12 +1147,12 @@ ProjectionBindingExpression projectionBindingExpression
.Select(p => p.ClrType)
.Any(t => t.IsNullableType());

var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
var outerKey = entityShaperExpression.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValueReadExpression(
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down
10 changes: 0 additions & 10 deletions src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,6 @@ public static IEnumerable<IColumnMapping> GetTableColumnMappings([NotNull] this
(IEnumerable<IColumnMapping>)property[RelationalAnnotationNames.TableColumnMappings]
?? Enumerable.Empty<IColumnMapping>();

/// <summary>
/// Returns the view or table columns to which the property is mapped.
/// </summary>
/// <param name="property"> The property. </param>
/// <returns> The view or table columns to which the property is mapped. </returns>
public static IEnumerable<IColumnMappingBase> GetViewOrTableColumnMappings([NotNull] this IProperty property) =>
(IEnumerable<IColumnMappingBase>)(property[RelationalAnnotationNames.ViewColumnMappings]
?? property[RelationalAnnotationNames.TableColumnMappings])
?? Enumerable.Empty<IColumnMappingBase>();

/// <summary>
/// Returns the view columns to which the property is mapped.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/IColumnBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IColumnBase : IAnnotatable
/// <summary>
/// Gets the column type.
/// </summary>
string Type { get; }
string StoreType { get; }

/// <summary>
/// Gets the value indicating whether the column can contain NULL.
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Metadata/Internal/Column.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Column : Annotatable, IColumn
public Column([NotNull] string name, [CanBeNull] string type, [NotNull] Table table)
{
Name = name;
Type = type;
StoreType = type;
Table = table;
}

Expand All @@ -37,7 +37,7 @@ public Column([NotNull] string name, [CanBeNull] string type, [NotNull] Table ta
public virtual ITable Table { get; }

/// <inheritdoc/>
public virtual string Type { get; }
public virtual string StoreType { get; }

/// <inheritdoc/>
public virtual bool IsNullable { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static string ToDebugString(

builder.Append(column.Name).Append(" (");

builder.Append(column.Type).Append(")");
builder.Append(column.StoreType).Append(")");

if (column.IsNullable)
{
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Metadata/Internal/ViewColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ViewColumn : Annotatable, IViewColumn
public ViewColumn([NotNull] string name, [NotNull] string type, [NotNull] View view)
{
Name = name;
Type = type;
StoreType = type;
View = view;
}

Expand All @@ -36,7 +36,7 @@ public ViewColumn([NotNull] string name, [NotNull] string type, [NotNull] View v
public virtual IView View { get; }

/// <inheritdoc/>
public virtual string Type { get; }
public virtual string StoreType { get; }

/// <inheritdoc/>
public virtual bool IsNullable { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static string ToDebugString(

builder.Append(column.Name).Append(" (");

builder.Append(column.Type).Append(")");
builder.Append(column.StoreType).Append(")");

if (column.IsNullable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,8 @@ protected virtual IEnumerable<MigrationOperation> Diff(
var sourceTypeMapping = sourceMapping.TypeMapping;
var targetTypeMapping = targetMapping.TypeMapping;

var sourceColumnType = source.Type ?? sourceTypeMapping.StoreType;
var targetColumnType = target.Type ?? targetTypeMapping.StoreType;
var sourceColumnType = source.StoreType ?? sourceTypeMapping.StoreType;
var targetColumnType = target.StoreType ?? targetTypeMapping.StoreType;

var sourceMigrationsAnnotations = source.GetAnnotations();
var targetMigrationsAnnotations = target.GetAnnotations();
Expand Down Expand Up @@ -1090,7 +1090,7 @@ private void Initialize(
= (valueConverter?.ProviderClrType
?? typeMapping.ClrType).UnwrapNullableType();

columnOperation.ColumnType = column.Type;
columnOperation.ColumnType = column.StoreType;
columnOperation.MaxLength = column.MaxLength;
columnOperation.Precision = column.Precision;
columnOperation.Scale = column.Scale;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ protected virtual string GetColumnType(
&& operation.IsFixedLength == column.IsFixedLength
&& operation.IsRowVersion == column.IsRowVersion)
{
return column.Type;
return column.StoreType;
}

keyOrIndex = table.UniqueConstraints.Any(u => u.Columns.Contains(column))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,12 @@ private Expression TryExpand(Expression source, MemberIdentity member)
var innerSequenceType = innerShapedQuery.Type.TryGetSequenceType();
var correlationPredicateParameter = Expression.Parameter(innerSequenceType);

var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
var outerKey = entityShaperExpression.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = correlationPredicateParameter.CreateKeyValueReadExpression(
var innerKey = correlationPredicateParameter.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down Expand Up @@ -1245,12 +1245,12 @@ private Expression TryExpand(Expression source, MemberIdentity member)
.Select(p => p.ClrType)
.Any(t => t.IsNullableType());

var outerKey = entityShaperExpression.CreateKeyValueReadExpression(
var outerKey = entityShaperExpression.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.Properties
: foreignKey.PrincipalKey.Properties,
makeNullable);
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValueReadExpression(
var innerKey = innerShapedQuery.ShaperExpression.CreateKeyValuesExpression(
navigation.IsOnDependent
? foreignKey.PrincipalKey.Properties
: foreignKey.Properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public SqliteAnnotationProvider([NotNull] RelationalAnnotationProviderDependenci
public override IEnumerable<IAnnotation> For(IRelationalModel model)
{
if (model.Tables.SelectMany(t => t.Columns).Any(
c => SqliteTypeMappingSource.IsSpatialiteType(c.Type)))
c => SqliteTypeMappingSource.IsSpatialiteType(c.StoreType)))
{
yield return new Annotation(SqliteAnnotationNames.InitSpatialMetaData, true);
}
Expand Down
Loading

0 comments on commit 5d85022

Please sign in to comment.