Skip to content

Commit eda1513

Browse files
authored
Add a read-optimized implementation of relational metadata.
Part of #8258
1 parent 847bf3d commit eda1513

File tree

75 files changed

+1394
-591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1394
-591
lines changed

src/EFCore.Cosmos/Storage/Internal/CosmosClientWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ public virtual async Task<bool> DeleteItemOnceAsync(
419419
{
420420
var entry = parameters.Entry;
421421
var items = Client.GetDatabase(_databaseId).GetContainer(parameters.ContainerId);
422-
422+
423423
var itemRequestOptions = CreateItemRequestOptions(entry);
424424
var partitionKey = CreatePartitionKey(entry);
425425

src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private void UpdateSequences(IReadOnlyModel model, string version)
157157
.Select(a => new Sequence(model, a.Name));
158158
#pragma warning restore CS0618 // Type or member is obsolete
159159

160-
var sequencesDictionary = new SortedDictionary<(string, string?), Sequence>();
160+
var sequencesDictionary = new SortedDictionary<(string, string?), ISequence>();
161161
foreach (var sequence in sequences)
162162
{
163163
sequencesDictionary[(sequence.Name, sequence.Schema)] = sequence;

src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,10 @@ public static string GetDefaultSqlQueryName([NotNull] this IReadOnlyEntityType e
445445
/// <returns> The SQL string used to provide data for the entity type. </returns>
446446
public static string? GetSqlQuery([NotNull] this IReadOnlyEntityType entityType)
447447
{
448-
var nameAnnotation = (string?)entityType[RelationalAnnotationNames.SqlQuery];
449-
if (nameAnnotation != null)
448+
var queryAnnotation = (string?)entityType[RelationalAnnotationNames.SqlQuery];
449+
if (queryAnnotation != null)
450450
{
451-
return nameAnnotation;
451+
return queryAnnotation;
452452
}
453453

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

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

718718
/// <summary>
719719
/// Returns all <see cref="ICheckConstraint" /> contained in the entity type.

src/EFCore.Relational/Extensions/RelationalModelBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private static Sequence HasSequence(
217217
Check.NotEmpty(name, nameof(name));
218218
Check.NullButNotEmpty(schema, nameof(schema));
219219

220-
var sequence = Sequence.FindSequence(model, name, schema);
220+
var sequence = (Sequence?)Sequence.FindSequence(model, name, schema);
221221
if (sequence != null)
222222
{
223223
sequence.UpdateConfigurationSource(configurationSource);

src/EFCore.Relational/Extensions/RelationalModelExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using System.Reflection;
78
using JetBrains.Annotations;
89
using Microsoft.EntityFrameworkCore.Diagnostics;
@@ -257,14 +258,14 @@ public static IEnumerable<ISequence> GetSequences([NotNull] this IModel model)
257258
/// </summary>
258259
/// <param name="model"> The model to get the sequences in. </param>
259260
public static IEnumerable<IMutableSequence> GetSequences([NotNull] this IMutableModel model)
260-
=> Sequence.GetSequences(Check.NotNull(model, nameof(model)));
261+
=> Sequence.GetSequences(Check.NotNull(model, nameof(model))).Cast<IMutableSequence>();
261262

262263
/// <summary>
263264
/// Returns all sequences contained in the model.
264265
/// </summary>
265266
/// <param name="model"> The model to get the sequences in. </param>
266267
public static IEnumerable<IConventionSequence> GetSequences([NotNull] this IConventionModel model)
267-
=> Sequence.GetSequences(Check.NotNull(model, nameof(model)));
268+
=> Sequence.GetSequences(Check.NotNull(model, nameof(model))).Cast<IConventionSequence>();
268269

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

468469
/// <summary>
469470
/// Returns all functions contained in the model.
470471
/// </summary>
471472
/// <param name="model"> The model to get the functions in. </param>
472473
public static IEnumerable<IConventionDbFunction> GetDbFunctions([NotNull] this IConventionModel model)
473-
=> DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model)));
474+
=> DbFunction.GetDbFunctions((Model)Check.NotNull(model, nameof(model))).Cast<IConventionDbFunction>();
474475

475476
/// <summary>
476477
/// Returns all functions contained in the model.

src/EFCore.Relational/Extensions/RelationalPropertyBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static bool CanSetColumnName(
123123
in StoreObjectIdentifier storeObject,
124124
bool fromDataAnnotation = false)
125125
{
126-
var overrides = RelationalPropertyOverrides.Find(propertyBuilder.Metadata, storeObject);
126+
var overrides = (RelationalPropertyOverrides?)RelationalPropertyOverrides.Find(propertyBuilder.Metadata, storeObject);
127127
return overrides == null
128128
|| (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention)
129129
.Overrides(overrides.GetColumnNameConfigurationSource())

src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static string GetColumnBaseName([NotNull] this IReadOnlyProperty property
5151
Check.NotNull(property, nameof(property));
5252

5353
var overrides = RelationalPropertyOverrides.Find(property, storeObject);
54-
if (overrides?.GetColumnNameConfigurationSource() != null)
54+
if (overrides?.ColumnNameOverriden == true)
5555
{
5656
return overrides.ColumnName;
5757
}
@@ -276,7 +276,7 @@ public static void SetColumnName(
276276
public static ConfigurationSource? GetColumnNameConfigurationSource(
277277
[NotNull] this IConventionProperty property,
278278
in StoreObjectIdentifier storeObject)
279-
=> RelationalPropertyOverrides.Find(property, storeObject)?.GetColumnNameConfigurationSource();
279+
=> ((RelationalPropertyOverrides?)RelationalPropertyOverrides.Find(property, storeObject))?.GetColumnNameConfigurationSource();
280280

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

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

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

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

14001399
/// <summary>
14011400
/// <para>
@@ -1412,7 +1411,7 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IRea
14121411
public static IMutableAnnotatable GetOrCreateOverrides(
14131412
[NotNull] this IMutableProperty property,
14141413
in StoreObjectIdentifier storeObject)
1415-
=> RelationalPropertyOverrides.GetOrCreate(property, storeObject);
1414+
=> (IMutableAnnotatable)RelationalPropertyOverrides.GetOrCreate(property, storeObject);
14161415

14171416
/// <summary>
14181417
/// <para>
@@ -1429,6 +1428,6 @@ public static IMutableAnnotatable GetOrCreateOverrides(
14291428
public static IConventionAnnotatable GetOrCreateOverrides(
14301429
[NotNull] this IConventionProperty property,
14311430
in StoreObjectIdentifier storeObject)
1432-
=> RelationalPropertyOverrides.GetOrCreate(property, storeObject);
1431+
=> (IConventionAnnotatable)RelationalPropertyOverrides.GetOrCreate(property, storeObject);
14331432
}
14341433
}

src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ protected virtual void ValidatePropertyOverrides(
11941194
{
11951195
foreach (var property in entityType.GetDeclaredProperties())
11961196
{
1197-
var tableOverrides = (SortedDictionary<StoreObjectIdentifier, RelationalPropertyOverrides>?)
1197+
var tableOverrides = (SortedDictionary<StoreObjectIdentifier, IRelationalPropertyOverrides>?)
11981198
property[RelationalAnnotationNames.RelationalOverrides];
11991199
if (tableOverrides == null)
12001200
{

src/EFCore.Relational/Metadata/Conventions/SequenceUniquificationConvention.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public virtual void ProcessModelFinalizing(
4141
{
4242
var model = modelBuilder.Metadata;
4343
var modelSequences =
44-
(SortedDictionary<(string Name, string Schema), Sequence>?)model[RelationalAnnotationNames.Sequences];
44+
(SortedDictionary<(string Name, string? Schema), ISequence>?)model[RelationalAnnotationNames.Sequences];
4545

4646
if (modelSequences != null)
4747
{
@@ -55,7 +55,7 @@ public virtual void ProcessModelFinalizing(
5555
var newSequenceName = Uniquifier.Uniquify(
5656
sequence.Key.Name, modelSequences,
5757
sequenceName => (sequenceName, schemaName), maxLength);
58-
Sequence.SetName((IMutableModel)model, sequence.Value, newSequenceName);
58+
Sequence.SetName((IMutableModel)model, (Sequence)sequence.Value, newSequenceName);
5959
}
6060
}
6161
}

src/EFCore.Relational/Metadata/ICheckConstraint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
1212
public interface ICheckConstraint : IReadOnlyCheckConstraint, IAnnotatable
1313
{
1414
/// <summary>
15-
/// Gets the <see cref="IEntityType" /> in which this check constraint is defined.
15+
/// Gets the entity type on which this check constraint is defined.
1616
/// </summary>
1717
new IEntityType EntityType { get; }
1818

src/EFCore.Relational/Metadata/IConventionCheckConstraint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ namespace Microsoft.EntityFrameworkCore.Metadata
99
public interface IConventionCheckConstraint : IReadOnlyCheckConstraint, IConventionAnnotatable
1010
{
1111
/// <summary>
12-
/// Gets the <see cref="IConventionEntityType" /> in which this check constraint is defined.
12+
/// Gets the entity type on which this check constraint is defined.
1313
/// </summary>
1414
new IConventionEntityType EntityType { get; }
1515

1616
/// <summary>
17-
/// Gets the configuration source for this <see cref="IConventionCheckConstraint" />.
17+
/// Gets the configuration source for this check constraint.
1818
/// </summary>
19-
/// <returns> The configuration source for <see cref="IConventionCheckConstraint" />. </returns>
19+
/// <returns> The configuration source for this check constraint. </returns>
2020
ConfigurationSource GetConfigurationSource();
2121
}
2222
}

src/EFCore.Relational/Metadata/IConventionDbFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
namespace Microsoft.EntityFrameworkCore.Metadata
1212
{
1313
/// <summary>
14-
/// Represents a relational database function in an <see cref="IConventionModel" /> in
15-
/// the a form that can be mutated while the model is being built.
14+
/// Represents a relational database function in a model in
15+
/// the form that can be mutated while the model is being built.
1616
/// </summary>
1717
public interface IConventionDbFunction : IReadOnlyDbFunction, IConventionAnnotatable
1818
{

src/EFCore.Relational/Metadata/IDbFunction.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
namespace Microsoft.EntityFrameworkCore.Metadata
88
{
99
/// <summary>
10-
/// Represents a relational database function in an <see cref="IModel" /> in
11-
/// the a form that can be mutated while the model is being built.
10+
/// Represents a relational database function in a model.
1211
/// </summary>
1312
public interface IDbFunction : IReadOnlyDbFunction, IAnnotatable
1413
{

src/EFCore.Relational/Metadata/IDbFunctionParameter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.EntityFrameworkCore.Infrastructure;
5-
using Microsoft.EntityFrameworkCore.Storage;
65

76
namespace Microsoft.EntityFrameworkCore.Metadata
87
{
@@ -11,6 +10,11 @@ namespace Microsoft.EntityFrameworkCore.Metadata
1110
/// </summary>
1211
public interface IDbFunctionParameter : IReadOnlyDbFunctionParameter, IAnnotatable
1312
{
13+
/// <summary>
14+
/// Gets the store type of this parameter.
15+
/// </summary>
16+
new string StoreType { get; }
17+
1418
/// <summary>
1519
/// Gets the function to which this parameter belongs.
1620
/// </summary>

src/EFCore.Relational/Metadata/IMutableCheckConstraint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
99
public interface IMutableCheckConstraint : IReadOnlyCheckConstraint, IMutableAnnotatable
1010
{
1111
/// <summary>
12-
/// Gets the <see cref="IMutableEntityType" /> in which this check constraint is defined.
12+
/// Gets the entity type on which this check constraint is defined.
1313
/// </summary>
1414
new IMutableEntityType EntityType { get; }
1515
}

src/EFCore.Relational/Metadata/IMutableDbFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
namespace Microsoft.EntityFrameworkCore.Metadata
1111
{
1212
/// <summary>
13-
/// Represents a relational database function in an <see cref="IMutableModel" /> in
14-
/// the a form that can be mutated while the model is being built.
13+
/// Represents a relational database function in an model in
14+
/// the form that can be mutated while the model is being built.
1515
/// </summary>
1616
public interface IMutableDbFunction : IReadOnlyDbFunction, IMutableAnnotatable
1717
{

src/EFCore.Relational/Metadata/IReadOnlyCheckConstraint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface IReadOnlyCheckConstraint : IReadOnlyAnnotatable
1616
string Name { get; }
1717

1818
/// <summary>
19-
/// Gets the <see cref="IReadOnlyEntityType" /> in which this check constraint is defined.
19+
/// Gets the entity type on which this check constraint is defined.
2020
/// </summary>
2121
IReadOnlyEntityType EntityType { get; }
2222

src/EFCore.Relational/Metadata/IReadOnlyDbFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace Microsoft.EntityFrameworkCore.Metadata
1515
{
1616
/// <summary>
17-
/// Represents a relational database function in an <see cref="IReadOnlyModel" />.
17+
/// Represents a relational database function in a model.
1818
/// </summary>
1919
public interface IReadOnlyDbFunction : IReadOnlyAnnotatable
2020
{

src/EFCore.Relational/Metadata/IReadOnlyDbFunctionParameter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Microsoft.EntityFrameworkCore.Metadata
1010
{
1111
/// <summary>
12-
/// Represents a <see cref="IReadOnlyDbFunction" /> parameter.
12+
/// Represents a function parameter.
1313
/// </summary>
1414
public interface IReadOnlyDbFunctionParameter : IReadOnlyAnnotatable
1515
{
@@ -34,8 +34,8 @@ public interface IReadOnlyDbFunctionParameter : IReadOnlyAnnotatable
3434
string? StoreType { get; }
3535

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

src/EFCore.Relational/Metadata/IReadOnlySequence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface IReadOnlySequence : IReadOnlyAnnotatable
2323
string? Schema { get; }
2424

2525
/// <summary>
26-
/// Gets the <see cref="IReadOnlyModel" /> in which this sequence is defined.
26+
/// Gets the model in which this sequence is defined.
2727
/// </summary>
2828
IReadOnlyModel Model { get; }
2929

src/EFCore.Relational/Metadata/ISequence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
1111
public interface ISequence : IReadOnlySequence, IAnnotatable
1212
{
1313
/// <summary>
14-
/// Gets the <see cref="IModel" /> in which this sequence is defined.
14+
/// Gets the model in which this sequence is defined.
1515
/// </summary>
1616
new IModel Model { get; }
1717
}

0 commit comments

Comments
 (0)