Class One<TEntity>
Represents a one-to-one relationship with an IEntity.
public class One<TEntity> where TEntity : IEntity
Type Parameters
TEntityAny type that implements IEntity
- Inheritance
-
One<TEntity>
- Inherited Members
Constructors
One()
public One()
One(string)
Initializes a reference to an entity in MongoDB.
public One(string id)
Parameters
idstringthe ID of the referenced entity
One(TEntity)
Initializes a reference to an entity in MongoDB.
public One(TEntity entity)
Parameters
entityTEntityThe actual entity this reference represents.
Properties
ID
The Id of the entity referenced by this instance.
[AsObjectId]
public string ID { get; set; }
Property Value
Methods
ToEntityAsync(DB, IClientSessionHandle?, CancellationToken)
Fetches the actual entity this reference represents from the database.
public Task<TEntity> ToEntityAsync(DB db, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Parameters
dbDBThe DB instance where these operations will be performed
sessionIClientSessionHandleAn optional session
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<TEntity>
A Task containing the actual entity
ToEntityAsync(Func<ProjectionDefinitionBuilder<TEntity>, ProjectionDefinition<TEntity, TEntity>>, DB, IClientSessionHandle?, CancellationToken)
Fetches the actual entity this reference represents from the database with a projection.
public Task<TEntity> ToEntityAsync(Func<ProjectionDefinitionBuilder<TEntity>, ProjectionDefinition<TEntity, TEntity>> projection, DB db, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Parameters
projectionFunc<ProjectionDefinitionBuilder<TEntity>, ProjectionDefinition<TEntity, TEntity>>p=> p.Include("Prop1").Exclude("Prop2")
dbDBThe DB instance where these operations will be performed
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<TEntity>
A Task containing the actual projected entity
Exceptions
- InvalidOperationException
thrown if the entity cannot be found in the database or more than one entity matching the ID is found.
ToEntityAsync(Expression<Func<TEntity, TEntity>>, DB, IClientSessionHandle?, CancellationToken)
Fetches the actual entity this reference represents from the database with a projection.
public Task<TEntity> ToEntityAsync(Expression<Func<TEntity, TEntity>> projection, DB db, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Parameters
projectionExpression<Func<TEntity, TEntity>>x => new Test { PropName = x.Prop }
dbDBThe DB instance where these operations will be performed
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<TEntity>
A Task containing the actual projected entity
Exceptions
- InvalidOperationException
thrown if the entity cannot be found in the database or more than one entity matching the ID is found.