Class CosmosEntityBuilder<TEntity>
Fluent configuration for one entity's Cosmos mapping.
public sealed class CosmosEntityBuilder<TEntity> where TEntity : class
Type Parameters
TEntityThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
descendingboolWhether the declared order is descending.
Returns
- CosmosEntityBuilder<TEntity>
Type Parameters
TMemberThe 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
selectorExpression<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
namestringThe 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
selectorExpression<Func<TEntity, TKey>>The id selector.
Returns
- CosmosEntityBuilder<TEntity>
Type Parameters
TKeyThe 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
selectorExpression<Func<TEntity, TKey>>The member selector (e.g.
x => x.CountryCode).pathstringAn explicit partition key path, or
nullto derive it from the member.
Returns
- CosmosEntityBuilder<TEntity>
Type Parameters
TKeyThe partition key member type.
TimeToLive(TimeSpan)
Sets the container's default time-to-live.
public CosmosEntityBuilder<TEntity> TimeToLive(TimeSpan timeToLive)
Parameters
timeToLiveTimeSpanThe default TTL.
Returns
- CosmosEntityBuilder<TEntity>