Table of Contents

Class CosmosEntityBuilder<TEntity>

Namespace
eQuantic.Core.Data.CosmosDb
Assembly
eQuantic.Core.Data.CosmosDb.dll

Fluent configuration for one entity's Cosmos mapping.

public sealed class CosmosEntityBuilder<TEntity> where TEntity : class

Type Parameters

TEntity

The entity type.

Inheritance
CosmosEntityBuilder<TEntity>
Inherited Members

Methods

ClusteringKey<TMember>(Expression<Func<TEntity, TMember>>, bool)

Declares an ordered-read member — materialized as a composite index on the container's indexing policy when two or more are declared (Cosmos needs no index declaration for a single ORDER BY).

public CosmosEntityBuilder<TEntity> ClusteringKey<TMember>(Expression<Func<TEntity, TMember>> selector, bool descending = false)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

descending bool

Whether the declared order is descending.

Returns

CosmosEntityBuilder<TEntity>

Type Parameters

TMember

The member type.

ConcurrencyToken(Expression<Func<TEntity, string?>>)

Declares the member holding the document's _etag (map it with [JsonPropertyName("_etag")] so reads populate it). When the member carries a value, a Modify/Merge stages a conditional replace (If-Match): a concurrent change makes the commit fail with a PreconditionFailed CosmosException instead of silently winning. Entities without a token (or with it unset) keep the unconditional last-write-wins upsert.

public CosmosEntityBuilder<TEntity> ConcurrencyToken(Expression<Func<TEntity, string?>> selector)

Parameters

selector Expression<Func<TEntity, string>>

The concurrency token member selector (e.g. x => x.ETag).

Returns

CosmosEntityBuilder<TEntity>

Container(string)

Sets the container name (defaults to the entity type name).

public CosmosEntityBuilder<TEntity> Container(string name)

Parameters

name string

The container name.

Returns

CosmosEntityBuilder<TEntity>

Id<TKey>(Expression<Func<TEntity, TKey>>)

Declares the document id selector. Defaults to the member annotated [EntityKey], or the entity's Id property (which serializes to the Cosmos id field); override it when the key is exposed differently.

public CosmosEntityBuilder<TEntity> Id<TKey>(Expression<Func<TEntity, TKey>> selector)

Parameters

selector Expression<Func<TEntity, TKey>>

The id selector.

Returns

CosmosEntityBuilder<TEntity>

Type Parameters

TKey

The id member type.

PartitionKey<TKey>(Expression<Func<TEntity, TKey>>, string?)

Declares a partition key level from a member selector — call once for a flat key, up to three times for a hierarchical (multi-hash) key, in order. The stored path derives from the member's stored name; pass path to override it. The first call replaces whatever the annotations seeded; subsequent calls append levels.

public CosmosEntityBuilder<TEntity> PartitionKey<TKey>(Expression<Func<TEntity, TKey>> selector, string? path = null)

Parameters

selector Expression<Func<TEntity, TKey>>

The member selector (e.g. x => x.CountryCode).

path string

An explicit partition key path, or null to derive it from the member.

Returns

CosmosEntityBuilder<TEntity>

Type Parameters

TKey

The partition key member type.

TimeToLive(TimeSpan)

Sets the container's default time-to-live.

public CosmosEntityBuilder<TEntity> TimeToLive(TimeSpan timeToLive)

Parameters

timeToLive TimeSpan

The default TTL.

Returns

CosmosEntityBuilder<TEntity>