Skip to content

Commit

Permalink
More tests and refactoring of how ElementTypes are created.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 6, 2023
1 parent c7bbe3a commit 478059e
Show file tree
Hide file tree
Showing 55 changed files with 3,853 additions and 3,348 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// 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>
/// Cosmos-specific extension methods for <see cref="PrimitiveCollectionBuilder" />.
/// </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>
public static class CosmosPrimitiveCollectionBuilderExtensions
{
/// <summary>
/// Configures the property name that the property is mapped to when targeting Azure Cosmos.
/// </summary>
/// <remarks>
/// <para>
/// If an empty string is supplied, the property will not be persisted.
/// </para>
/// <para>
/// 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.
/// </para>
/// </remarks>
/// <param name="primitiveCollectionBuilder">The builder for the property being configured.</param>
/// <param name="name">The name of the property.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static PrimitiveCollectionBuilder ToJsonProperty(
this PrimitiveCollectionBuilder primitiveCollectionBuilder,
string name)
{
Check.NotNull(name, nameof(name));

primitiveCollectionBuilder.Metadata.SetJsonPropertyName(name);

return primitiveCollectionBuilder;
}

/// <summary>
/// Configures the property name that the property is mapped to when targeting Azure Cosmos.
/// </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>
/// <param name="name">The name of the property.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
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);
}
Loading

0 comments on commit 478059e

Please sign in to comment.