Skip to content

Commit

Permalink
Add a read-optimized implementation of relational metadata.
Browse files Browse the repository at this point in the history
Part of #8258
  • Loading branch information
AndriySvyryd authored Mar 16, 2021
1 parent 847bf3d commit eda1513
Show file tree
Hide file tree
Showing 75 changed files with 1,394 additions and 591 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public virtual async Task<bool> DeleteItemOnceAsync(
{
var entry = parameters.Entry;
var items = Client.GetDatabase(_databaseId).GetContainer(parameters.ContainerId);

var itemRequestOptions = CreateItemRequestOptions(entry);
var partitionKey = CreatePartitionKey(entry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void UpdateSequences(IReadOnlyModel model, string version)
.Select(a => new Sequence(model, a.Name));
#pragma warning restore CS0618 // Type or member is obsolete

var sequencesDictionary = new SortedDictionary<(string, string?), Sequence>();
var sequencesDictionary = new SortedDictionary<(string, string?), ISequence>();
foreach (var sequence in sequences)
{
sequencesDictionary[(sequence.Name, sequence.Schema)] = sequence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,10 @@ public static string GetDefaultSqlQueryName([NotNull] this IReadOnlyEntityType e
/// <returns> The SQL string used to provide data for the entity type. </returns>
public static string? GetSqlQuery([NotNull] this IReadOnlyEntityType entityType)
{
var nameAnnotation = (string?)entityType[RelationalAnnotationNames.SqlQuery];
if (nameAnnotation != null)
var queryAnnotation = (string?)entityType[RelationalAnnotationNames.SqlQuery];
if (queryAnnotation != null)
{
return nameAnnotation;
return queryAnnotation;
}

if (entityType.BaseType != null)
Expand Down Expand Up @@ -706,14 +706,14 @@ public static IEnumerable<IReadOnlyCheckConstraint> GetCheckConstraints([NotNull
/// </summary>
/// <param name="entityType"> The entity type to get the check constraints for. </param>
public static IEnumerable<IMutableCheckConstraint> GetCheckConstraints([NotNull] this IMutableEntityType entityType)
=> CheckConstraint.GetCheckConstraints(entityType);
=> CheckConstraint.GetCheckConstraints(entityType).Cast<IMutableCheckConstraint>();

/// <summary>
/// Returns all <see cref="IConventionCheckConstraint" /> contained in the entity type.
/// </summary>
/// <param name="entityType"> The entity type to get the check constraints for. </param>
public static IEnumerable<IConventionCheckConstraint> GetCheckConstraints([NotNull] this IConventionEntityType entityType)
=> CheckConstraint.GetCheckConstraints(entityType);
=> CheckConstraint.GetCheckConstraints(entityType).Cast<IConventionCheckConstraint>();

/// <summary>
/// Returns all <see cref="ICheckConstraint" /> contained in the entity type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static Sequence HasSequence(
Check.NotEmpty(name, nameof(name));
Check.NullButNotEmpty(schema, nameof(schema));

var sequence = Sequence.FindSequence(model, name, schema);
var sequence = (Sequence?)Sequence.FindSequence(model, name, schema);
if (sequence != null)
{
sequence.UpdateConfigurationSource(configurationSource);
Expand Down
9 changes: 5 additions & 4 deletions src/EFCore.Relational/Extensions/RelationalModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
Expand Down Expand Up @@ -257,14 +258,14 @@ public static IEnumerable<ISequence> GetSequences([NotNull] this IModel model)
/// </summary>
/// <param name="model"> The model to get the sequences in. </param>
public static IEnumerable<IMutableSequence> GetSequences([NotNull] this IMutableModel model)
=> Sequence.GetSequences(Check.NotNull(model, nameof(model)));
=> Sequence.GetSequences(Check.NotNull(model, nameof(model))).Cast<IMutableSequence>();

/// <summary>
/// Returns all sequences contained in the model.
/// </summary>
/// <param name="model"> The model to get the sequences in. </param>
public static IEnumerable<IConventionSequence> GetSequences([NotNull] this IConventionModel model)
=> Sequence.GetSequences(Check.NotNull(model, nameof(model)));
=> Sequence.GetSequences(Check.NotNull(model, nameof(model))).Cast<IConventionSequence>();

/// <summary>
/// Returns all sequences contained in the model.
Expand Down Expand Up @@ -463,14 +464,14 @@ public static IEnumerable<IReadOnlyDbFunction> GetDbFunctions([NotNull] this IMo
/// </summary>
/// <param name="model"> The model to get the functions in. </param>
public static IEnumerable<IMutableDbFunction> GetDbFunctions([NotNull] this IMutableModel model)
=> DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model)));
=> DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model))).Cast<IMutableDbFunction>();

/// <summary>
/// Returns all functions contained in the model.
/// </summary>
/// <param name="model"> The model to get the functions in. </param>
public static IEnumerable<IConventionDbFunction> GetDbFunctions([NotNull] this IConventionModel model)
=> DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model)));
=> DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model))).Cast<IConventionDbFunction>();

/// <summary>
/// Returns all functions contained in the model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static bool CanSetColumnName(
in StoreObjectIdentifier storeObject,
bool fromDataAnnotation = false)
{
var overrides = RelationalPropertyOverrides.Find(propertyBuilder.Metadata, storeObject);
var overrides = (RelationalPropertyOverrides?)RelationalPropertyOverrides.Find(propertyBuilder.Metadata, storeObject);
return overrides == null
|| (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention)
.Overrides(overrides.GetColumnNameConfigurationSource())
Expand Down
17 changes: 8 additions & 9 deletions src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static string GetColumnBaseName([NotNull] this IReadOnlyProperty property
Check.NotNull(property, nameof(property));

var overrides = RelationalPropertyOverrides.Find(property, storeObject);
if (overrides?.GetColumnNameConfigurationSource() != null)
if (overrides?.ColumnNameOverriden == true)
{
return overrides.ColumnName;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ public static void SetColumnName(
public static ConfigurationSource? GetColumnNameConfigurationSource(
[NotNull] this IConventionProperty property,
in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject)?.GetColumnNameConfigurationSource();
=> ((RelationalPropertyOverrides?)RelationalPropertyOverrides.Find(property, storeObject))?.GetColumnNameConfigurationSource();

/// <summary>
/// Returns the database type of the column to which the property is mapped, or <see langword="null" /> if the database type
Expand Down Expand Up @@ -1063,8 +1063,7 @@ public static void SetComment([NotNull] this IMutableProperty property, [CanBeNu
/// <param name="property"> The property. </param>
/// <returns> The <see cref="ConfigurationSource" /> for the column comment. </returns>
public static ConfigurationSource? GetCommentConfigurationSource([NotNull] this IConventionProperty property)
=> property.FindAnnotation(RelationalAnnotationNames.Comment)
?.GetConfigurationSource();
=> property.FindAnnotation(RelationalAnnotationNames.Comment)?.GetConfigurationSource();

/// <summary>
/// Returns the collation to be used for the column.
Expand Down Expand Up @@ -1365,7 +1364,7 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IRea
/// <param name="storeObject"> The identifier of the table-like store object containing the column. </param>
/// <returns> An object that stores property facet overrides. </returns>
public static IMutableAnnotatable? FindOverrides([NotNull] this IMutableProperty property, in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject);
=> (IMutableAnnotatable?)RelationalPropertyOverrides.Find(property, storeObject);

/// <summary>
/// <para>
Expand All @@ -1380,7 +1379,7 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IRea
/// <param name="storeObject"> The identifier of the table-like store object containing the column. </param>
/// <returns> An object that stores property facet overrides. </returns>
public static IConventionAnnotatable? FindOverrides([NotNull] this IConventionProperty property, in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject);
=> (IConventionAnnotatable?)RelationalPropertyOverrides.Find(property, storeObject);

/// <summary>
/// <para>
Expand All @@ -1395,7 +1394,7 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IRea
/// <param name="storeObject"> The identifier of the table-like store object containing the column. </param>
/// <returns> An object that stores property facet overrides. </returns>
public static IAnnotatable? FindOverrides([NotNull] this IProperty property, in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject);
=> (IAnnotatable?)RelationalPropertyOverrides.Find(property, storeObject);

/// <summary>
/// <para>
Expand All @@ -1412,7 +1411,7 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IRea
public static IMutableAnnotatable GetOrCreateOverrides(
[NotNull] this IMutableProperty property,
in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.GetOrCreate(property, storeObject);
=> (IMutableAnnotatable)RelationalPropertyOverrides.GetOrCreate(property, storeObject);

/// <summary>
/// <para>
Expand All @@ -1429,6 +1428,6 @@ public static IMutableAnnotatable GetOrCreateOverrides(
public static IConventionAnnotatable GetOrCreateOverrides(
[NotNull] this IConventionProperty property,
in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.GetOrCreate(property, storeObject);
=> (IConventionAnnotatable)RelationalPropertyOverrides.GetOrCreate(property, storeObject);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ protected virtual void ValidatePropertyOverrides(
{
foreach (var property in entityType.GetDeclaredProperties())
{
var tableOverrides = (SortedDictionary<StoreObjectIdentifier, RelationalPropertyOverrides>?)
var tableOverrides = (SortedDictionary<StoreObjectIdentifier, IRelationalPropertyOverrides>?)
property[RelationalAnnotationNames.RelationalOverrides];
if (tableOverrides == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public virtual void ProcessModelFinalizing(
{
var model = modelBuilder.Metadata;
var modelSequences =
(SortedDictionary<(string Name, string Schema), Sequence>?)model[RelationalAnnotationNames.Sequences];
(SortedDictionary<(string Name, string? Schema), ISequence>?)model[RelationalAnnotationNames.Sequences];

if (modelSequences != null)
{
Expand All @@ -55,7 +55,7 @@ public virtual void ProcessModelFinalizing(
var newSequenceName = Uniquifier.Uniquify(
sequence.Key.Name, modelSequences,
sequenceName => (sequenceName, schemaName), maxLength);
Sequence.SetName((IMutableModel)model, sequence.Value, newSequenceName);
Sequence.SetName((IMutableModel)model, (Sequence)sequence.Value, newSequenceName);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/ICheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
public interface ICheckConstraint : IReadOnlyCheckConstraint, IAnnotatable
{
/// <summary>
/// Gets the <see cref="IEntityType" /> in which this check constraint is defined.
/// Gets the entity type on which this check constraint is defined.
/// </summary>
new IEntityType EntityType { get; }

Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ namespace Microsoft.EntityFrameworkCore.Metadata
public interface IConventionCheckConstraint : IReadOnlyCheckConstraint, IConventionAnnotatable
{
/// <summary>
/// Gets the <see cref="IConventionEntityType" /> in which this check constraint is defined.
/// Gets the entity type on which this check constraint is defined.
/// </summary>
new IConventionEntityType EntityType { get; }

/// <summary>
/// Gets the configuration source for this <see cref="IConventionCheckConstraint" />.
/// Gets the configuration source for this check constraint.
/// </summary>
/// <returns> The configuration source for <see cref="IConventionCheckConstraint" />. </returns>
/// <returns> The configuration source for this check constraint. </returns>
ConfigurationSource GetConfigurationSource();
}
}
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Metadata/IConventionDbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
/// Represents a relational database function in an <see cref="IConventionModel" /> in
/// the a form that can be mutated while the model is being built.
/// Represents a relational database function in a model in
/// the form that can be mutated while the model is being built.
/// </summary>
public interface IConventionDbFunction : IReadOnlyDbFunction, IConventionAnnotatable
{
Expand Down
3 changes: 1 addition & 2 deletions src/EFCore.Relational/Metadata/IDbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
/// Represents a relational database function in an <see cref="IModel" /> in
/// the a form that can be mutated while the model is being built.
/// Represents a relational database function in a model.
/// </summary>
public interface IDbFunction : IReadOnlyDbFunction, IAnnotatable
{
Expand Down
6 changes: 5 additions & 1 deletion src/EFCore.Relational/Metadata/IDbFunctionParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

namespace Microsoft.EntityFrameworkCore.Metadata
{
Expand All @@ -11,6 +10,11 @@ namespace Microsoft.EntityFrameworkCore.Metadata
/// </summary>
public interface IDbFunctionParameter : IReadOnlyDbFunctionParameter, IAnnotatable
{
/// <summary>
/// Gets the store type of this parameter.
/// </summary>
new string StoreType { get; }

/// <summary>
/// Gets the function to which this parameter belongs.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/IMutableCheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
public interface IMutableCheckConstraint : IReadOnlyCheckConstraint, IMutableAnnotatable
{
/// <summary>
/// Gets the <see cref="IMutableEntityType" /> in which this check constraint is defined.
/// Gets the entity type on which this check constraint is defined.
/// </summary>
new IMutableEntityType EntityType { get; }
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Metadata/IMutableDbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
/// Represents a relational database function in an <see cref="IMutableModel" /> in
/// the a form that can be mutated while the model is being built.
/// Represents a relational database function in an model in
/// the form that can be mutated while the model is being built.
/// </summary>
public interface IMutableDbFunction : IReadOnlyDbFunction, IMutableAnnotatable
{
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/IReadOnlyCheckConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IReadOnlyCheckConstraint : IReadOnlyAnnotatable
string Name { get; }

/// <summary>
/// Gets the <see cref="IReadOnlyEntityType" /> in which this check constraint is defined.
/// Gets the entity type on which this check constraint is defined.
/// </summary>
IReadOnlyEntityType EntityType { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/IReadOnlyDbFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
/// Represents a relational database function in an <see cref="IReadOnlyModel" />.
/// Represents a relational database function in a model.
/// </summary>
public interface IReadOnlyDbFunction : IReadOnlyAnnotatable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Microsoft.EntityFrameworkCore.Metadata
{
/// <summary>
/// Represents a <see cref="IReadOnlyDbFunction" /> parameter.
/// Represents a function parameter.
/// </summary>
public interface IReadOnlyDbFunctionParameter : IReadOnlyAnnotatable
{
Expand All @@ -34,8 +34,8 @@ public interface IReadOnlyDbFunctionParameter : IReadOnlyAnnotatable
string? StoreType { get; }

/// <summary>
/// Gets the value which indicates whether parameter propagates nullability, meaning if it's value is null the database function itself
/// returns null.
/// Gets the value which indicates whether the parameter propagates nullability,
/// meaning if it's value is <see langword="null"/> the database function itself returns <see langword="null"/>.
/// </summary>
bool PropagatesNullability { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/IReadOnlySequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IReadOnlySequence : IReadOnlyAnnotatable
string? Schema { get; }

/// <summary>
/// Gets the <see cref="IReadOnlyModel" /> in which this sequence is defined.
/// Gets the model in which this sequence is defined.
/// </summary>
IReadOnlyModel Model { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/ISequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
public interface ISequence : IReadOnlySequence, IAnnotatable
{
/// <summary>
/// Gets the <see cref="IModel" /> in which this sequence is defined.
/// Gets the model in which this sequence is defined.
/// </summary>
new IModel Model { get; }
}
Expand Down
Loading

0 comments on commit eda1513

Please sign in to comment.