Skip to content

Commit

Permalink
Create PrimitiveCollection top-level internal method.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 9, 2023
1 parent d8a0276 commit 423bc0b
Show file tree
Hide file tree
Showing 22 changed files with 433 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;

namespace Microsoft.EntityFrameworkCore;

/// <summary>
Expand Down Expand Up @@ -55,37 +53,4 @@ public static PrimitiveCollectionBuilder<TProperty> ToJsonProperty<TProperty>(
this PrimitiveCollectionBuilder<TProperty> primitiveCollectionBuilder,
string name)
=> (PrimitiveCollectionBuilder<TProperty>)ToJsonProperty((PrimitiveCollectionBuilder)primitiveCollectionBuilder, name);

/// <summary>
/// Configures this property to be the etag concurrency token.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="primitiveCollectionBuilder">The builder for the property being configured.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static PrimitiveCollectionBuilder IsETagConcurrency(this PrimitiveCollectionBuilder primitiveCollectionBuilder)
{
primitiveCollectionBuilder
.IsConcurrencyToken()
.ToJsonProperty("_etag")
.ValueGeneratedOnAddOrUpdate();

return primitiveCollectionBuilder;
}

/// <summary>
/// Configures this property to be the etag concurrency token.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <typeparam name="TProperty">The type of the property being configured.</typeparam>
/// <param name="primitiveCollectionBuilder">The builder for the property being configured.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static PrimitiveCollectionBuilder<TProperty> IsETagConcurrency<TProperty>(
this PrimitiveCollectionBuilder<TProperty> primitiveCollectionBuilder)
=> (PrimitiveCollectionBuilder<TProperty>)IsETagConcurrency((PrimitiveCollectionBuilder)primitiveCollectionBuilder);
}
14 changes: 6 additions & 8 deletions src/EFCore/Metadata/Builders/ComplexPropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ public virtual ComplexTypePropertyBuilder Property(Type propertyType, string pro
/// <returns>An object that can be used to configure the property.</returns>
public virtual ComplexTypePrimitiveCollectionBuilder PrimitiveCollection(string propertyName)
=> new(
TypeBuilder.Property(
TypeBuilder.PrimitiveCollection(
Check.NotEmpty(propertyName, nameof(propertyName)),
ConfigurationSource.Explicit)!.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Returns an object that can be used to configure a property of the complex type.
Expand All @@ -235,10 +235,9 @@ public virtual ComplexTypePrimitiveCollectionBuilder PrimitiveCollection(string
/// <returns>An object that can be used to configure the property.</returns>
public virtual ComplexTypePrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProperty>(string propertyName)
=> new(
TypeBuilder.Property(
TypeBuilder.PrimitiveCollection(
typeof(TProperty),
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Returns an object that can be used to configure a property of the complex type.
Expand All @@ -256,10 +255,9 @@ public virtual ComplexTypePrimitiveCollectionBuilder<TProperty> PrimitiveCollect
/// <returns>An object that can be used to configure the property.</returns>
public virtual ComplexTypePrimitiveCollectionBuilder PrimitiveCollection(Type propertyType, string propertyName)
=> new(
TypeBuilder.Property(
TypeBuilder.PrimitiveCollection(
Check.NotNull(propertyType, nameof(propertyType)),
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Returns an object that can be used to configure a property of the complex type.
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Builders/ComplexPropertyBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public virtual ComplexTypePropertyBuilder<TProperty> Property<TProperty>(Express
/// </param>
/// <returns>An object that can be used to configure the property.</returns>
public virtual ComplexTypePrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProperty>(Expression<Func<TComplex, TProperty>> propertyExpression)
=> new(TypeBuilder.Property(
=> new(TypeBuilder.PrimitiveCollection(
Check.NotNull(propertyExpression, nameof(propertyExpression)).GetMemberAccess(), ConfigurationSource.Explicit)!
.Metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public virtual ComplexTypePrimitiveCollectionBuilder HasField(string fieldName)
/// </summary>
/// <returns>A builder to configure the collection element type.</returns>
public virtual ElementTypeBuilder ElementType()
=> new((IMutableElementType)Builder.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata.GetElementType()!);
=> new((IMutableElementType)Builder.Metadata.GetElementType()!);

/// <summary>
/// Configures the elements of this collection.
Expand Down
15 changes: 6 additions & 9 deletions src/EFCore/Metadata/Builders/EntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ public virtual PropertyBuilder Property(Type propertyType, string propertyName)
/// <returns>An object that can be used to configure the property.</returns>
public virtual PrimitiveCollectionBuilder PrimitiveCollection(string propertyName)
=> new(
Builder.Property(
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
Builder.PrimitiveCollection(
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Returns an object that can be used to configure a property of the entity type where that property represents
Expand All @@ -204,10 +203,9 @@ public virtual PrimitiveCollectionBuilder PrimitiveCollection(string propertyNam
/// <returns>An object that can be used to configure the property.</returns>
public virtual PrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProperty>(string propertyName)
=> new(
Builder.Property(
Builder.PrimitiveCollection(
typeof(TProperty),
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Returns an object that can be used to configure a property of the entity type where that property represents
Expand All @@ -226,10 +224,9 @@ public virtual PrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProper
/// <returns>An object that can be used to configure the property.</returns>
public virtual PrimitiveCollectionBuilder PrimitiveCollection(Type propertyType, string propertyName)
=> new(
Builder.Property(
Builder.PrimitiveCollection(
Check.NotNull(propertyType, nameof(propertyType)),
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Returns an object that can be used to configure a property of the entity type.
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/Builders/EntityTypeBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public virtual PropertyBuilder<TProperty> Property<TProperty>(Expression<Func<TE
public virtual PrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProperty>(
Expression<Func<TEntity, TProperty>> propertyExpression)
=> new(
Builder.Property(Check.NotNull(propertyExpression, nameof(propertyExpression)).GetMemberAccess(),
ConfigurationSource.Explicit)!.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
Builder.PrimitiveCollection(Check.NotNull(propertyExpression, nameof(propertyExpression)).GetMemberAccess(),
ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Configures a complex property of the entity type.
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,13 @@ bool CanSetProviderValueComparer(
/// 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>
IConventionElementTypeBuilder? PrimitiveCollection(bool fromDataAnnotation = false);
IConventionElementTypeBuilder? ElementType(bool fromDataAnnotation = false);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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>
bool CanSetPrimitiveCollection(bool fromDataAnnotation = false);
bool CanSetElementType(bool fromDataAnnotation = false);
}
15 changes: 6 additions & 9 deletions src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ public virtual PropertyBuilder Property(Type propertyType, string propertyName)
public virtual PrimitiveCollectionBuilder PrimitiveCollection(string propertyName)
=> UpdateBuilder(
() => new PrimitiveCollectionBuilder(
DependentEntityType.Builder.Property(
DependentEntityType.Builder.PrimitiveCollection(
Check.NotEmpty(propertyName, nameof(propertyName)),
ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata));
ConfigurationSource.Explicit)!.Metadata));

/// <summary>
/// Returns an object that can be used to configure a property of the owned type where that property represents
Expand All @@ -229,10 +228,9 @@ public virtual PrimitiveCollectionBuilder PrimitiveCollection(string propertyNam
public virtual PrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProperty>(string propertyName)
=> UpdateBuilder(
() => new PrimitiveCollectionBuilder<TProperty>(
DependentEntityType.Builder.Property(
DependentEntityType.Builder.PrimitiveCollection(
typeof(TProperty),
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata));
Check.NotEmpty(propertyName, nameof(propertyName)), ConfigurationSource.Explicit)!.Metadata));

/// <summary>
/// Returns an object that can be used to configure a property of the owned type where that property represents
Expand All @@ -251,10 +249,9 @@ public virtual PrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProper
/// <returns>An object that can be used to configure the property.</returns>
public virtual PrimitiveCollectionBuilder PrimitiveCollection(Type propertyType, string propertyName)
=> new(
DependentEntityType.Builder.Property(
DependentEntityType.Builder.PrimitiveCollection(
Check.NotNull(propertyType, nameof(propertyType)), Check.NotEmpty(propertyName, nameof(propertyName)),
ConfigurationSource.Explicit)!
.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata);
ConfigurationSource.Explicit)!.Metadata);

/// <summary>
/// Returns an object that can be used to configure a property of the entity type.
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public virtual PropertyBuilder<TProperty> PrimitiveCollection<TProperty>(
Expression<Func<TDependentEntity, TProperty>> propertyExpression)
=> UpdateBuilder(
() => new PropertyBuilder<TProperty>(
DependentEntityType.Builder.Property(
DependentEntityType.Builder.PrimitiveCollection(
Check.NotNull(propertyExpression, nameof(propertyExpression)).GetMemberAccess(),
ConfigurationSource.Explicit)!.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata));
ConfigurationSource.Explicit)!.Metadata));

/// <summary>
/// Returns an object that can be used to configure an existing navigation property
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Builders/PrimitiveCollectionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public virtual PrimitiveCollectionBuilder HasField(string fieldName)
/// </summary>
/// <returns>A builder to configure the collection element type.</returns>
public virtual ElementTypeBuilder ElementType()
=> new((IMutableElementType)Builder.PrimitiveCollection(ConfigurationSource.Explicit)!.Metadata.GetElementType()!);
=> new((IMutableElementType)Builder.Metadata.GetElementType()!);

/// <summary>
/// Configures the elements of this collection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IElementTypeAnnotationChangedConvention : IConvention
/// <param name="annotation">The new annotation.</param>
/// <param name="oldAnnotation">The old annotation.</param>
/// <param name="context">Additional information associated with convention execution.</param>
void ProcessPropertyAnnotationChanged(
void ProcessElementTypeAnnotationChanged(
IConventionElementTypeBuilder builder,
string name,
IConventionAnnotation? annotation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IElementTypeNullabilityChangedConvention : IConvention
/// </summary>
/// <param name="builder">The builder for the element.</param>
/// <param name="context">Additional information associated with convention execution.</param>
void ProcessPropertyNullabilityChanged(
void ProcessElementTypeNullabilityChanged(
IConventionElementTypeBuilder builder,
IConventionContext<bool?> context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ public IConventionModelBuilder OnModelInitialized(IConventionModelBuilder modelB
return null;
}

elementConvention.ProcessPropertyNullabilityChanged(builder, _boolConventionContext);
elementConvention.ProcessElementTypeNullabilityChanged(builder, _boolConventionContext);
if (_boolConventionContext.ShouldStopProcessing())
{
return _boolConventionContext.Result;
Expand Down Expand Up @@ -1704,7 +1704,7 @@ public IConventionModelBuilder OnModelInitialized(IConventionModelBuilder modelB
_annotationConventionContext.ResetState(annotation);
foreach (var elementConvention in _conventionSet.ElementTypeAnnotationChangedConventions)
{
elementConvention.ProcessPropertyAnnotationChanged(
elementConvention.ProcessElementTypeAnnotationChanged(
builder, name, annotation, oldAnnotation, _annotationConventionContext);

if (_annotationConventionContext.ShouldStopProcessing())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void Process(IConventionEntityTypeBuilder entityTypeBuilder)
var propertyBuilder = entityTypeBuilder.Property(propertyInfo);
if (mapping?.ElementTypeMapping != null)
{
propertyBuilder?.PrimitiveCollection();
propertyBuilder?.ElementType();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/ElementType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public virtual void SetRemovedFromModel()
/// 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 new virtual IConventionAnnotation? OnAnnotationSet(
protected override IConventionAnnotation? OnAnnotationSet(
string name,
IConventionAnnotation? annotation,
IConventionAnnotation? oldAnnotation)
Expand Down
Loading

0 comments on commit 423bc0b

Please sign in to comment.