Class MongoEntityBuilder<TEntity>
Fluent configuration for one entity's MongoDB mapping.
public sealed class MongoEntityBuilder<TEntity> where TEntity : class
Type Parameters
TEntityThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
descendingboolWhether the declared order is descending.
Returns
- MongoEntityBuilder<TEntity>
Type Parameters
TMemberThe member type.
Collection(string)
Sets the collection name (defaults to [Entity("...")], then the type name).
public MongoEntityBuilder<TEntity> Collection(string name)
Parameters
namestringThe 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
selectorExpression<Func<TEntity, TMember>>The member selector (e.g.
x => x.Version).
Returns
- MongoEntityBuilder<TEntity>
Type Parameters
TMemberThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
toStoredFunc<TMember, TStored>Converts the CLR value to its stored representation.
fromStoredFunc<TStored, TMember>Converts the stored representation back.
Returns
- MongoEntityBuilder<TEntity>
Type Parameters
TMemberThe member's CLR type.
TStoredThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
elementNamestringThe stored element name.
Returns
- MongoEntityBuilder<TEntity>
Type Parameters
TMemberThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
Returns
- MongoEntityBuilder<TEntity>
Type Parameters
TMemberThe 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
selectorExpression<Func<TEntity, TMember>>The member selector.
Returns
- MongoEntityBuilder<TEntity>
Type Parameters
TMemberThe 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
selectorExpression<Func<TEntity, TMember>>The date member the expiry counts from (e.g.
x => x.CreatedAt).timeToLiveTimeSpanThe lifetime after that date.
Returns
- MongoEntityBuilder<TEntity>
Type Parameters
TMemberThe date member type.