Table of Contents

Class Many<TChild, TParent>

Namespace
MongoDB.Entities
Assembly
MongoDB.Entities.dll

Represents a one-to-many/many-to-many relationship between two Entities.

WARNING: You have to initialize all instances of this class before accessing any of its members.

Initialize from the constructor of the parent entity as follows:

this.InitOneToMany(() => Property);

this.InitManyToMany(() => Property, x => x.OtherProperty);

public sealed class Many<TChild, TParent> : ManyBase, IEnumerable<TChild>, IEnumerable where TChild : IEntity where TParent : IEntity

Type Parameters

TChild

Type of the child IEntity.

TParent

The type of the parent

Inheritance
Many<TChild, TParent>
Implements
IEnumerable<TChild>
Inherited Members
Extension Methods

Constructors

Many()

Creates an instance of Many<TChild> This is only needed in VB.Net

public Many()

Properties

JoinCollection

Gets the IMongoCollection of JoinRecords for this relationship.

TIP: Try never to use this unless really necessary.

public IMongoCollection<JoinRecord> JoinCollection { get; }

Property Value

IMongoCollection<JoinRecord>

Methods

AddAsync(IEnumerable<object?>, IClientSessionHandle?, CancellationToken)

Adds multiple child references in a single bulk operation

WARNING: Make sure to save the parent and child Entities before calling this method.

public Task AddAsync(IEnumerable<object?> childIDs, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

childIDs IEnumerable<object>

The IDs of the child Entities to add.

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

AddAsync(IEnumerable<TChild>, IClientSessionHandle?, CancellationToken)

Adds multiple child references in a single bulk operation

WARNING: Make sure to save the parent and child Entities before calling this method.

public Task AddAsync(IEnumerable<TChild> children, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

children IEnumerable<TChild>

The child Entities to add

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

AddAsync(object, IClientSessionHandle?, CancellationToken)

Adds a new child reference.

WARNING: Make sure to save the parent and child Entities before calling this method.

public Task AddAsync(object childID, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

childID object

The ID of the child Entity to add.

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

AddAsync(TChild, IClientSessionHandle?, CancellationToken)

Adds a new child reference.

WARNING: Make sure to save the parent and child Entities before calling this method.

public Task AddAsync(TChild child, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

child TChild

The child Entity to add.

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

ChildrenCountAsync(IClientSessionHandle?, CountOptions?, CancellationToken)

Get the number of children for a relationship

public Task<long> ChildrenCountAsync(IClientSessionHandle? session = null, CountOptions? options = null, CancellationToken cancellation = default)

Parameters

session IClientSessionHandle

An optional session if using within a transaction

options CountOptions

An optional AggregateOptions object

cancellation CancellationToken

An optional cancellation token

Returns

Task<long>

ChildrenFluent(IClientSessionHandle?, AggregateOptions?)

An IAggregateFluent of child Entities for the parent.

public IAggregateFluent<TChild> ChildrenFluent(IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IAggregateFluent<TChild>

ChildrenQueryable(IClientSessionHandle?, AggregateOptions?)

An IQueryable of child Entities for the parent.

public IQueryable<TChild> ChildrenQueryable(IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IQueryable<TChild>

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<TChild> GetEnumerator()

Returns

IEnumerator<TChild>

An enumerator that can be used to iterate through the collection.

JoinFluent(IClientSessionHandle?, AggregateOptions?)

An IAggregateFluent of JoinRecords for this relationship

public IAggregateFluent<JoinRecord> JoinFluent(IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IAggregateFluent<JoinRecord>

JoinQueryable(IClientSessionHandle?, AggregateOptions?)

An IQueryable of JoinRecords for this relationship

public IQueryable<JoinRecord> JoinQueryable(IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IQueryable<JoinRecord>

ParentsFluent(ObjectId, IClientSessionHandle?, AggregateOptions?)

Get an IAggregateFluent of parents matching a single child ID for this relationship.

public IAggregateFluent<TParent> ParentsFluent(ObjectId childID, IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

childID ObjectId

A child ID

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IAggregateFluent<TParent>

ParentsFluent(IAggregateFluent<TChild>)

Get an IAggregateFluent of parents matching a supplied IAggregateFluent of children for this relationship.

public IAggregateFluent<TParent> ParentsFluent(IAggregateFluent<TChild> children)

Parameters

children IAggregateFluent<TChild>

An IAggregateFluent of children

Returns

IAggregateFluent<TParent>

ParentsFluent(IEnumerable<object>, IClientSessionHandle?, AggregateOptions?)

Get an IAggregateFluent of parents matching multiple child IDs for this relationship.

public IAggregateFluent<TParent> ParentsFluent(IEnumerable<object> childIDs, IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

childIDs IEnumerable<object>

An IEnumerable of child IDs

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IAggregateFluent<TParent>

ParentsFluent(Guid, IClientSessionHandle?, AggregateOptions?)

Get an IAggregateFluent of parents matching a single child ID for this relationship.

public IAggregateFluent<TParent> ParentsFluent(Guid childID, IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

childID Guid

A child ID

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IAggregateFluent<TParent>

ParentsFluent(long, IClientSessionHandle?, AggregateOptions?)

Get an IAggregateFluent of parents matching a single child ID for this relationship.

public IAggregateFluent<TParent> ParentsFluent(long childID, IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

childID long

A child ID

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IAggregateFluent<TParent>

ParentsFluent(string, IClientSessionHandle?, AggregateOptions?)

Get an IAggregateFluent of parents matching a single child ID for this relationship.

public IAggregateFluent<TParent> ParentsFluent(string childID, IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

childID string

A child ID

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IAggregateFluent<TParent>

ParentsQueryable(IEnumerable<string>, IClientSessionHandle?, AggregateOptions?)

Get an IQueryable of parents matching multiple child IDs for this relationship.

public IQueryable<TParent> ParentsQueryable(IEnumerable<string> childIDs, IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

childIDs IEnumerable<string>

An IEnumerable of child IDs

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IQueryable<TParent>

ParentsQueryable(string, IClientSessionHandle?, AggregateOptions?)

Get an IQueryable of parents matching a single child ID for this relationship.

public IQueryable<TParent> ParentsQueryable(string childID, IClientSessionHandle? session = null, AggregateOptions? options = null)

Parameters

childID string

A child ID

session IClientSessionHandle

An optional session if using within a transaction

options AggregateOptions

An optional AggregateOptions object

Returns

IQueryable<TParent>

RemoveAsync(IEnumerable<object?>, IClientSessionHandle?, CancellationToken)

Removes child references.

public Task RemoveAsync(IEnumerable<object?> childIDs, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

childIDs IEnumerable<object>

The IDs of the child Entities to remove the references of

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

RemoveAsync(IEnumerable<TChild>, IClientSessionHandle?, CancellationToken)

Removes child references.

public Task RemoveAsync(IEnumerable<TChild> children, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

children IEnumerable<TChild>

The child Entities to remove the references of.

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

RemoveAsync(object, IClientSessionHandle?, CancellationToken)

Removes a child reference.

public Task RemoveAsync(object childID, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

childID object

The ID of the child Entity to remove the reference of.

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

RemoveAsync(TChild, IClientSessionHandle?, CancellationToken)

Removes a child reference.

public Task RemoveAsync(TChild child, IClientSessionHandle? session = null, CancellationToken cancellation = default)

Parameters

child TChild

The child IEntity to remove the reference of.

session IClientSessionHandle

An optional session if using within a transaction

cancellation CancellationToken

An optional cancellation token

Returns

Task

VB_InitManyToMany(TParent, Expression<Func<TParent, object?>>, Expression<Func<TChild, object?>>, bool)

Use this method to initialize the Many<TChild> properties with VB.Net

public void VB_InitManyToMany(TParent parent, Expression<Func<TParent, object?>> propertyParent, Expression<Func<TChild, object?>> propertyChild, bool isInverse)

Parameters

parent TParent

The parent entity instance

propertyParent Expression<Func<TParent, object>>

Function(x) x.ParentProp

propertyChild Expression<Func<TChild, object>>

Function(x) x.ChildProp

isInverse bool

Specify if this is the inverse side of the relationship or not

VB_InitOneToMany(TParent, Expression<Func<TParent, object?>>)

Use this method to initialize the Many<TChild> properties with VB.Net

public void VB_InitOneToMany(TParent parent, Expression<Func<TParent, object?>> property)

Parameters

parent TParent

The parent entity instance

property Expression<Func<TParent, object>>

Function(x) x.PropName