Skip to content

Commit b988989

Browse files
authored
API review updates: (#34403)
- Rename `AlwaysCreateShadowIdProperty` to `HasShadowId` and `HasShadowIds` (on the model builder) - Rename `IncludeDiscriminatorInJsonId` to `HasDiscriminatorInJsonId` and `HasDiscriminatorInJsonIds`. Same for the related methods - Rename `DiscriminatorInKeyBehavior` to `IdDiscriminatorMode` and move it to `Microsoft.EntityFrameworkCore.Metadata` - Rename `DiscriminatorInKeyBehavior.(Root)EntityTypeName` to `(Root)EntityType` - Move `ETagPropertyConvention` to `Microsoft.EntityFrameworkCore.Metadata.Conventions` - Consider merging `CosmosKeyAugmenterConvention` with `CosmosKeyDiscoveryConvention`, otherwise propose a better name for it. - Tried it. Got messy. Renamed to `CosmosPartitionKeyInPrimaryKeyConvention`. I'm sure it will be dicussed again. - Check why the obsolete methods on `RelationalSqlTranslatingExpressionVisitor` haven't been removed in the initial pass - Because it seems we didn't do the pass at the start of EF9
1 parent 4df2f55 commit b988989

35 files changed

+146
-148
lines changed

src/EFCore.Cosmos/Extensions/CosmosEntityTypeBuilderExtensions.cs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.EntityFrameworkCore.Cosmos.Metadata;
54
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
65

76
// ReSharper disable once CheckNamespace
@@ -406,11 +405,11 @@ public static EntityTypeBuilder<TEntity> UseETagConcurrency<TEntity>(this Entity
406405
/// <see langword="null" /> to revert to the default setting.
407406
/// </param>
408407
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
409-
public static EntityTypeBuilder AlwaysCreateShadowIdProperty(
408+
public static EntityTypeBuilder HasShadowId(
410409
this EntityTypeBuilder entityTypeBuilder,
411410
bool? alwaysCreate = true)
412411
{
413-
entityTypeBuilder.Metadata.SetAlwaysCreateShadowIdProperty(alwaysCreate);
412+
entityTypeBuilder.Metadata.SetHasShadowId(alwaysCreate);
414413

415414
return entityTypeBuilder;
416415
}
@@ -430,11 +429,11 @@ public static EntityTypeBuilder AlwaysCreateShadowIdProperty(
430429
/// <see langword="null" /> to revert to the default setting.
431430
/// </param>
432431
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
433-
public static EntityTypeBuilder<TEntity> AlwaysCreateShadowIdProperty<TEntity>(
432+
public static EntityTypeBuilder<TEntity> HasShadowId<TEntity>(
434433
this EntityTypeBuilder<TEntity> entityTypeBuilder,
435434
bool? alwaysCreate = true)
436435
where TEntity : class
437-
=> (EntityTypeBuilder<TEntity>)AlwaysCreateShadowIdProperty((EntityTypeBuilder)entityTypeBuilder, alwaysCreate);
436+
=> (EntityTypeBuilder<TEntity>)HasShadowId((EntityTypeBuilder)entityTypeBuilder, alwaysCreate);
438437

439438
/// <summary>
440439
/// Forces model building to always create a "__id" shadow property mapped to the JSON "id". This was the default
@@ -451,17 +450,17 @@ public static EntityTypeBuilder<TEntity> AlwaysCreateShadowIdProperty<TEntity>(
451450
/// </param>
452451
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
453452
/// <returns>The same builder instance if the configuration was applied, <see langword="null" /> otherwise.</returns>
454-
public static IConventionEntityTypeBuilder? AlwaysCreateShadowIdProperty(
453+
public static IConventionEntityTypeBuilder? HasShadowId(
455454
this IConventionEntityTypeBuilder entityTypeBuilder,
456455
bool? alwaysCreate,
457456
bool fromDataAnnotation = false)
458457
{
459-
if (!entityTypeBuilder.CanSetAlwaysCreateShadowIdProperty(alwaysCreate, fromDataAnnotation))
458+
if (!entityTypeBuilder.CanSetShadowId(alwaysCreate, fromDataAnnotation))
460459
{
461460
return null;
462461
}
463462

464-
entityTypeBuilder.Metadata.SetAlwaysCreateShadowIdProperty(alwaysCreate, fromDataAnnotation);
463+
entityTypeBuilder.Metadata.SetHasShadowId(alwaysCreate, fromDataAnnotation);
465464

466465
return entityTypeBuilder;
467466
}
@@ -481,14 +480,14 @@ public static EntityTypeBuilder<TEntity> AlwaysCreateShadowIdProperty<TEntity>(
481480
/// </param>
482481
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
483482
/// <returns><see langword="true" /> if the configuration can be applied.</returns>
484-
public static bool CanSetAlwaysCreateShadowIdProperty(
483+
public static bool CanSetShadowId(
485484
this IConventionEntityTypeBuilder entityTypeBuilder,
486485
bool? alwaysCreate,
487486
bool fromDataAnnotation = false)
488487
{
489488
Check.NotNull(entityTypeBuilder, nameof(entityTypeBuilder));
490489

491-
return entityTypeBuilder.CanSetAnnotation(CosmosAnnotationNames.AlwaysCreateShadowIdProperty, alwaysCreate, fromDataAnnotation);
490+
return entityTypeBuilder.CanSetAnnotation(CosmosAnnotationNames.HasShadowId, alwaysCreate, fromDataAnnotation);
492491
}
493492

494493
/// <summary>
@@ -504,16 +503,16 @@ public static bool CanSetAlwaysCreateShadowIdProperty(
504503
/// <see langword="null" /> to revert to the default setting.
505504
/// </param>
506505
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
507-
public static EntityTypeBuilder IncludeDiscriminatorInJsonId(
506+
public static EntityTypeBuilder HasDiscriminatorInJsonId(
508507
this EntityTypeBuilder entityTypeBuilder,
509508
bool? includeDiscriminator = true)
510509
{
511510
entityTypeBuilder.Metadata.SetDiscriminatorInKey(
512511
includeDiscriminator == null
513512
? null
514513
: includeDiscriminator.Value
515-
? DiscriminatorInKeyBehavior.EntityTypeName
516-
: DiscriminatorInKeyBehavior.None);
514+
? IdDiscriminatorMode.EntityType
515+
: IdDiscriminatorMode.None);
517516

518517
return entityTypeBuilder;
519518
}
@@ -540,8 +539,8 @@ public static EntityTypeBuilder IncludeRootDiscriminatorInJsonId(
540539
includeDiscriminator == null
541540
? null
542541
: includeDiscriminator.Value
543-
? DiscriminatorInKeyBehavior.RootEntityTypeName
544-
: DiscriminatorInKeyBehavior.None);
542+
? IdDiscriminatorMode.RootEntityType
543+
: IdDiscriminatorMode.None);
545544

546545
return entityTypeBuilder;
547546
}
@@ -559,10 +558,10 @@ public static EntityTypeBuilder IncludeRootDiscriminatorInJsonId(
559558
/// <see langword="null" /> to revert to the default setting.
560559
/// </param>
561560
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
562-
public static EntityTypeBuilder<TEntity> IncludeDiscriminatorInJsonId<TEntity>(
561+
public static EntityTypeBuilder<TEntity> HasDiscriminatorInJsonId<TEntity>(
563562
this EntityTypeBuilder<TEntity> entityTypeBuilder, bool? includeDiscriminator = true)
564563
where TEntity : class
565-
=> (EntityTypeBuilder<TEntity>)IncludeDiscriminatorInJsonId((EntityTypeBuilder)entityTypeBuilder, includeDiscriminator);
564+
=> (EntityTypeBuilder<TEntity>)HasDiscriminatorInJsonId((EntityTypeBuilder)entityTypeBuilder, includeDiscriminator);
566565

567566
/// <summary>
568567
/// Includes the discriminator value of the root entity type in the JSON "id" value. This allows types with the same
@@ -597,10 +596,10 @@ public static EntityTypeBuilder<TEntity> IncludeRootDiscriminatorInJsonId<TEntit
597596
/// </param>
598597
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
599598
/// <returns>The same builder instance if the configuration was applied, <see langword="null" /> otherwise.</returns>
600-
public static IConventionEntityTypeBuilder? IncludeDiscriminatorInJsonId(
599+
public static IConventionEntityTypeBuilder? HasDiscriminatorInJsonId(
601600
this IConventionEntityTypeBuilder entityTypeBuilder, bool? includeDiscriminator, bool fromDataAnnotation = false)
602601
{
603-
if (!entityTypeBuilder.CanSetIncludeDiscriminatorInJsonId(includeDiscriminator, fromDataAnnotation))
602+
if (!entityTypeBuilder.CanSetDiscriminatorInJsonId(includeDiscriminator, fromDataAnnotation))
604603
{
605604
return null;
606605
}
@@ -609,8 +608,8 @@ public static EntityTypeBuilder<TEntity> IncludeRootDiscriminatorInJsonId<TEntit
609608
includeDiscriminator == null
610609
? null
611610
: includeDiscriminator.Value
612-
? DiscriminatorInKeyBehavior.EntityTypeName
613-
: DiscriminatorInKeyBehavior.None, fromDataAnnotation);
611+
? IdDiscriminatorMode.EntityType
612+
: IdDiscriminatorMode.None, fromDataAnnotation);
614613

615614
return entityTypeBuilder;
616615
}
@@ -642,8 +641,8 @@ public static EntityTypeBuilder<TEntity> IncludeRootDiscriminatorInJsonId<TEntit
642641
includeDiscriminator == null
643642
? null
644643
: includeDiscriminator.Value
645-
? DiscriminatorInKeyBehavior.EntityTypeName
646-
: DiscriminatorInKeyBehavior.None, fromDataAnnotation);
644+
? IdDiscriminatorMode.EntityType
645+
: IdDiscriminatorMode.None, fromDataAnnotation);
647646

648647
return entityTypeBuilder;
649648
}
@@ -663,7 +662,7 @@ public static EntityTypeBuilder<TEntity> IncludeRootDiscriminatorInJsonId<TEntit
663662
/// </param>
664663
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
665664
/// <returns><see langword="true" /> if the configuration can be applied.</returns>
666-
public static bool CanSetIncludeDiscriminatorInJsonId(
665+
public static bool CanSetDiscriminatorInJsonId(
667666
this IConventionEntityTypeBuilder entityTypeBuilder,
668667
bool? includeDiscriminator,
669668
bool fromDataAnnotation = false)
@@ -675,8 +674,8 @@ public static bool CanSetIncludeDiscriminatorInJsonId(
675674
includeDiscriminator == null
676675
? null
677676
: includeDiscriminator.Value
678-
? DiscriminatorInKeyBehavior.EntityTypeName
679-
: DiscriminatorInKeyBehavior.None, fromDataAnnotation);
677+
? IdDiscriminatorMode.EntityType
678+
: IdDiscriminatorMode.None, fromDataAnnotation);
680679
}
681680

682681

@@ -707,8 +706,8 @@ public static bool CanSetIncludeRootDiscriminatorInJsonId(
707706
includeDiscriminator == null
708707
? null
709708
: includeDiscriminator.Value
710-
? DiscriminatorInKeyBehavior.RootEntityTypeName
711-
: DiscriminatorInKeyBehavior.None, fromDataAnnotation);
709+
? IdDiscriminatorMode.RootEntityType
710+
: IdDiscriminatorMode.None, fromDataAnnotation);
712711
}
713712

714713
/// <summary>

src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.EntityFrameworkCore.Cosmos.Metadata;
54
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
65

76
// ReSharper disable once CheckNamespace
@@ -354,11 +353,11 @@ public static void SetETagPropertyName(this IMutableEntityType entityType, strin
354353
/// <see langword="true" /> to force __id creation, <see langword="false" /> to not force __id creation,
355354
/// <see langword="null" /> to revert to the default setting.
356355
/// .</returns>
357-
public static bool? GetAlwaysCreateShadowIdProperty(this IReadOnlyEntityType entityType)
356+
public static bool? GetHasShadowId(this IReadOnlyEntityType entityType)
358357
=> (entityType.BaseType != null
359-
? entityType.GetRootType().GetAlwaysCreateShadowIdProperty()
360-
: (bool?)entityType[CosmosAnnotationNames.AlwaysCreateShadowIdProperty])
361-
?? entityType.Model.GetAlwaysCreateShadowIdProperty();
358+
? entityType.GetRootType().GetHasShadowId()
359+
: (bool?)entityType[CosmosAnnotationNames.HasShadowId])
360+
?? entityType.Model.GetHasShadowIds();
362361

363362
/// <summary>
364363
/// Forces model building to always create a "__id" shadow property mapped to the JSON "id". This was the default
@@ -369,8 +368,8 @@ public static void SetETagPropertyName(this IMutableEntityType entityType, strin
369368
/// <see langword="true" /> to force __id creation, <see langword="false" /> to not force __id creation,
370369
/// <see langword="null" /> to revert to the default setting.
371370
/// </param>
372-
public static void SetAlwaysCreateShadowIdProperty(this IMutableEntityType entityType, bool? alwaysCreate)
373-
=> entityType.SetOrRemoveAnnotation(CosmosAnnotationNames.AlwaysCreateShadowIdProperty, alwaysCreate);
371+
public static void SetHasShadowId(this IMutableEntityType entityType, bool? alwaysCreate)
372+
=> entityType.SetOrRemoveAnnotation(CosmosAnnotationNames.HasShadowId, alwaysCreate);
374373

375374
/// <summary>
376375
/// Forces model building to always create a "__id" shadow property mapped to the JSON "id". This was the default
@@ -382,39 +381,39 @@ public static void SetAlwaysCreateShadowIdProperty(this IMutableEntityType entit
382381
/// <see langword="null" /> to revert to the default setting.
383382
/// </param>
384383
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
385-
public static bool? SetAlwaysCreateShadowIdProperty(
384+
public static bool? SetHasShadowId(
386385
this IConventionEntityType entityType,
387386
bool? alwaysCreate,
388387
bool fromDataAnnotation = false)
389388
=> (bool?)entityType.SetOrRemoveAnnotation(
390-
CosmosAnnotationNames.AlwaysCreateShadowIdProperty, alwaysCreate, fromDataAnnotation)?.Value;
389+
CosmosAnnotationNames.HasShadowId, alwaysCreate, fromDataAnnotation)?.Value;
391390

392391
/// <summary>
393-
/// Gets the <see cref="ConfigurationSource" /> for <see cref="GetAlwaysCreateShadowIdProperty"/>.
392+
/// Gets the <see cref="ConfigurationSource" /> for <see cref="GetHasShadowId"/>.
394393
/// </summary>
395394
/// <param name="entityType">The entity typer.</param>
396395
/// <returns>The <see cref="ConfigurationSource" />.</returns>
397-
public static ConfigurationSource? GetAlwaysCreateShadowIdPropertyConfigurationSource(this IConventionEntityType entityType)
398-
=> entityType.FindAnnotation(CosmosAnnotationNames.AlwaysCreateShadowIdProperty)?.GetConfigurationSource();
396+
public static ConfigurationSource? GetHasShadowIdConfigurationSource(this IConventionEntityType entityType)
397+
=> entityType.FindAnnotation(CosmosAnnotationNames.HasShadowId)?.GetConfigurationSource();
399398

400399
/// <summary>
401400
/// Returns a value indicating whether the entity type discriminator should be included in the JSON "id" value.
402401
/// Prior to EF Core 9, it was always included. Starting with EF Core 9, it is not included by default.
403402
/// </summary>
404403
/// <param name="entityType">The entity type.</param>
405-
/// <returns>The <see cref="DiscriminatorInKeyBehavior"/> or <see langword="null" /> if not set.</returns>
406-
public static DiscriminatorInKeyBehavior? GetDiscriminatorInKey(this IReadOnlyEntityType entityType)
404+
/// <returns>The <see cref="IdDiscriminatorMode"/> or <see langword="null" /> if not set.</returns>
405+
public static IdDiscriminatorMode? GetDiscriminatorInKey(this IReadOnlyEntityType entityType)
407406
=> (entityType.BaseType != null
408407
? entityType.GetRootType().GetDiscriminatorInKey()
409-
: (DiscriminatorInKeyBehavior?)entityType[CosmosAnnotationNames.DiscriminatorInKey])
408+
: (IdDiscriminatorMode?)entityType[CosmosAnnotationNames.DiscriminatorInKey])
410409
?? entityType.Model.GetDiscriminatorInKey();
411410

412411
/// <summary>
413412
/// Includes the entity type discriminator in the JSON "id".
414413
/// </summary>
415414
/// <param name="entityType">The entity type.</param>
416415
/// <param name="behavior">The behavior to use, or <see langword="null" /> to reset the behavior to the default.</param>
417-
public static void SetDiscriminatorInKey(this IMutableEntityType entityType, DiscriminatorInKeyBehavior? behavior)
416+
public static void SetDiscriminatorInKey(this IMutableEntityType entityType, IdDiscriminatorMode? behavior)
418417
=> entityType.SetOrRemoveAnnotation(CosmosAnnotationNames.DiscriminatorInKey, behavior);
419418

420419
/// <summary>
@@ -423,9 +422,9 @@ public static void SetDiscriminatorInKey(this IMutableEntityType entityType, Dis
423422
/// <param name="entityType">The entity type.</param>
424423
/// <param name="behavior">The behavior to use, or <see langword="null" /> to reset the behavior to the default.</param>
425424
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
426-
public static DiscriminatorInKeyBehavior? SetDiscriminatorInKey(
427-
this IConventionEntityType entityType, DiscriminatorInKeyBehavior? behavior, bool fromDataAnnotation = false)
428-
=> (DiscriminatorInKeyBehavior?)entityType.SetOrRemoveAnnotation(
425+
public static IdDiscriminatorMode? SetDiscriminatorInKey(
426+
this IConventionEntityType entityType, IdDiscriminatorMode? behavior, bool fromDataAnnotation = false)
427+
=> (IdDiscriminatorMode?)entityType.SetOrRemoveAnnotation(
429428
CosmosAnnotationNames.DiscriminatorInKey, behavior, fromDataAnnotation)?.Value;
430429

431430
/// <summary>

src/EFCore.Cosmos/Extensions/CosmosModelBuilderExtensions.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.EntityFrameworkCore.Cosmos.Metadata;
54
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
65

76
// ReSharper disable once CheckNamespace
@@ -118,9 +117,9 @@ public static ModelBuilder HasManualThroughput(this ModelBuilder modelBuilder, i
118117
/// <see langword="true" /> to force __id creation, <see langword="false" /> to not force __id creation,
119118
/// <see langword="null" /> to revert to the default setting.
120119
/// </param>
121-
public static ModelBuilder AlwaysCreateShadowIdProperties(this ModelBuilder modelBuilder, bool? alwaysCreate = true)
120+
public static ModelBuilder HasShadowIds(this ModelBuilder modelBuilder, bool? alwaysCreate = true)
122121
{
123-
modelBuilder.Model.SetAlwaysCreateShadowIdProperty(alwaysCreate);
122+
modelBuilder.Model.SetHasShadowIds(alwaysCreate);
124123

125124
return modelBuilder;
126125
}
@@ -138,16 +137,16 @@ public static ModelBuilder AlwaysCreateShadowIdProperties(this ModelBuilder mode
138137
/// <see langword="null" /> to revert to the default setting.
139138
/// </param>
140139
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
141-
public static ModelBuilder IncludeDiscriminatorInJsonId(
140+
public static ModelBuilder HasDiscriminatorInJsonIds(
142141
this ModelBuilder modelBuilder,
143142
bool? includeDiscriminator = true)
144143
{
145144
modelBuilder.Model.SetDiscriminatorInKey(
146145
includeDiscriminator == null
147146
? null
148147
: includeDiscriminator.Value
149-
? DiscriminatorInKeyBehavior.EntityTypeName
150-
: DiscriminatorInKeyBehavior.None);
148+
? IdDiscriminatorMode.EntityType
149+
: IdDiscriminatorMode.None);
151150

152151
return modelBuilder;
153152
}
@@ -174,8 +173,8 @@ public static ModelBuilder IncludeRootDiscriminatorInJsonId(
174173
includeDiscriminator == null
175174
? null
176175
: includeDiscriminator.Value
177-
? DiscriminatorInKeyBehavior.RootEntityTypeName
178-
: DiscriminatorInKeyBehavior.None);
176+
? IdDiscriminatorMode.RootEntityType
177+
: IdDiscriminatorMode.None);
179178

180179
return modelBuilder;
181180
}

0 commit comments

Comments
 (0)