Table of Contents

Class One<TEntity, TIdentity>

Namespace
MongoDB.Entities
Assembly
MongoDB.Entities.dll

Represents a one-to-one relationship with an IEntity.

public class One<TEntity, TIdentity> where TEntity : IEntity where TIdentity : notnull

Type Parameters

TEntity

Any type that implements IEntity

TIdentity

The type of the ID property

Inheritance
One<TEntity, TIdentity>
Inherited Members

Constructors

One()

public One()

One(TEntity)

Initializes a reference to an entity in MongoDB.

public One(TEntity entity)

Parameters

entity TEntity

The actual entity this reference represents.

One(TIdentity)

Initializes a reference to an entity in MongoDB.

public One(TIdentity id)

Parameters

id TIdentity

the ID of the referenced entity

Properties

ID

The Id of the entity referenced by this instance.

public TIdentity ID { get; set; }

Property Value

TIdentity

Methods

FromObject(TIdentity)

Operator for returning a new One<T> object from an object ID

public static One<TEntity, TIdentity> FromObject(TIdentity id)

Parameters

id TIdentity

The ID to create a new One<T> with

Returns

One<TEntity, TIdentity>

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

db DB

The DB instance where these operations will be performed

session IClientSessionHandle

An optional session

cancellation CancellationToken

An 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

projection Func<ProjectionDefinitionBuilder<TEntity>, ProjectionDefinition<TEntity, TEntity>>

p=> p.Include("Prop1").Exclude("Prop2")

db DB

The DB instance where these operations will be performed

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An 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

projection Expression<Func<TEntity, TEntity>>

x => new Test { PropName = x.Prop }

db DB

The DB instance where these operations will be performed

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An 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.