Table of Contents

Class MongoEntityBuilder<TEntity>

Namespace
eQuantic.Core.Data.MongoDb
Assembly
eQuantic.Core.Data.MongoDb.dll

Fluent configuration for one entity's MongoDB mapping.

public sealed class MongoEntityBuilder<TEntity> where TEntity : class

Type Parameters

TEntity

The entity type.

Inheritance
MongoEntityBuilder<TEntity>
Inherited Members

Methods

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

Declares an ordered-read member — materialized as one compound index with the declared directions by the migration's EnsureCollection(). Call in order for several.

public MongoEntityBuilder<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

MongoEntityBuilder<TEntity>

Type Parameters

TMember

The member type.

Collection(string)

Sets the collection name (defaults to [Entity("...")], then the type name).

public MongoEntityBuilder<TEntity> Collection(string name)

Parameters

name string

The collection name.

Returns

MongoEntityBuilder<TEntity>

ConcurrencyToken<TMember>(Expression<Func<TEntity, TMember>>)

Declares the optimistic-concurrency member: an integral version the entity carries. A staged replace filters on the read version and writes the bump; a commit whose replace matched nothing throws ConcurrencyConflictException — another writer changed (or removed) the document since it was read. Entities without a token keep plain last-write-wins replaces.

public MongoEntityBuilder<TEntity> ConcurrencyToken<TMember>(Expression<Func<TEntity, TMember>> selector)

Parameters

selector Expression<Func<TEntity, TMember>>

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

Returns

MongoEntityBuilder<TEntity>

Type Parameters

TMember

The version member type (an integral type).

Converts<TMember, TStored>(Expression<Func<TEntity, TMember>>, Func<TMember, TStored>, Func<TStored, TMember>)

Declares a value conversion for the member: documents store TStored, the entity keeps TMember. Filters, sorts and set-based updates on the member render against the stored representation — the driver serializes constants through the member's serializer.

public MongoEntityBuilder<TEntity> Converts<TMember, TStored>(Expression<Func<TEntity, TMember>> selector, Func<TMember, TStored> toStored, Func<TStored, TMember> fromStored)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

toStored Func<TMember, TStored>

Converts the CLR value to its stored representation.

fromStored Func<TStored, TMember>

Converts the stored representation back.

Returns

MongoEntityBuilder<TEntity>

Type Parameters

TMember

The member's CLR type.

TStored

The stored (BSON) type.

Field<TMember>(Expression<Func<TEntity, TMember>>, string)

Sets the member's BSON element name when the convention (the member name) does not fit.

public MongoEntityBuilder<TEntity> Field<TMember>(Expression<Func<TEntity, TMember>> selector, string elementName)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

elementName string

The stored element name.

Returns

MongoEntityBuilder<TEntity>

Type Parameters

TMember

The member type.

Ignore<TMember>(Expression<Func<TEntity, TMember>>)

Excludes the member from the mapping (it neither persists nor reads back).

public MongoEntityBuilder<TEntity> Ignore<TMember>(Expression<Func<TEntity, TMember>> selector)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

Returns

MongoEntityBuilder<TEntity>

Type Parameters

TMember

The member type.

Key<TMember>(Expression<Func<TEntity, TMember>>)

Declares the member the document's _id (defaults to [EntityKey], then Id).

public MongoEntityBuilder<TEntity> Key<TMember>(Expression<Func<TEntity, TMember>> selector)

Parameters

selector Expression<Func<TEntity, TMember>>

The member selector.

Returns

MongoEntityBuilder<TEntity>

Type Parameters

TMember

The member type.

TimeToLive<TMember>(Expression<Func<TEntity, TMember>>, TimeSpan)

Declares the TTL index: each document expires timeToLive after the date its selector member carries (MongoDB's per-document expiry — unlike Cosmos DB's container default). The migration's EnsureCollection() creates the index.

public MongoEntityBuilder<TEntity> TimeToLive<TMember>(Expression<Func<TEntity, TMember>> selector, TimeSpan timeToLive)

Parameters

selector Expression<Func<TEntity, TMember>>

The date member the expiry counts from (e.g. x => x.CreatedAt).

timeToLive TimeSpan

The lifetime after that date.

Returns

MongoEntityBuilder<TEntity>

Type Parameters

TMember

The date member type.