-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata for primitive collection mapping
Part of #30730 Some stuff remaining, but wanted to get this out there for initial review. Missing: - ElementType in compiled model - Negative cases - More tests Review updates Change builder shape based on API review Updated based on review. More tests and refactoring of how ElementTypes are created.
- Loading branch information
1 parent
0ee3ac8
commit d8a0276
Showing
97 changed files
with
12,468 additions
and
2,143 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/EFCore.Cosmos/Extensions/CosmosPrimitiveCollectionBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.