Class Many<TChild, TParent>
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
TChildType of the child IEntity.
TParentThe 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
childIDsIEnumerable<object>The IDs of the child Entities to add.
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
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
childrenIEnumerable<TChild>The child Entities to add
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
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
childIDobjectThe ID of the child Entity to add.
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
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
childTChildThe child Entity to add.
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
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
sessionIClientSessionHandleAn optional session if using within a transaction
optionsCountOptionsAn optional AggregateOptions object
cancellationCancellationTokenAn optional cancellation token
Returns
ChildrenFluent(IClientSessionHandle?, AggregateOptions?)
An IAggregateFluent of child Entities for the parent.
public IAggregateFluent<TChild> ChildrenFluent(IClientSessionHandle? session = null, AggregateOptions? options = null)
Parameters
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn optional AggregateOptions object
Returns
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
childIDObjectIdA child ID
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
childrenIAggregateFluent<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
childIDsIEnumerable<object>An IEnumerable of child IDs
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
childIDGuidA child ID
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
childIDlongA child ID
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
childIDstringA child ID
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
childIDsIEnumerable<string>An IEnumerable of child IDs
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
childIDstringA child ID
sessionIClientSessionHandleAn optional session if using within a transaction
optionsAggregateOptionsAn 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
childIDsIEnumerable<object>The IDs of the child Entities to remove the references of
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
RemoveAsync(IEnumerable<TChild>, IClientSessionHandle?, CancellationToken)
Removes child references.
public Task RemoveAsync(IEnumerable<TChild> children, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Parameters
childrenIEnumerable<TChild>The child Entities to remove the references of.
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
RemoveAsync(object, IClientSessionHandle?, CancellationToken)
Removes a child reference.
public Task RemoveAsync(object childID, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Parameters
childIDobjectThe ID of the child Entity to remove the reference of.
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
RemoveAsync(TChild, IClientSessionHandle?, CancellationToken)
Removes a child reference.
public Task RemoveAsync(TChild child, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Parameters
childTChildThe child IEntity to remove the reference of.
sessionIClientSessionHandleAn optional session if using within a transaction
cancellationCancellationTokenAn optional cancellation token
Returns
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
parentTParentThe parent entity instance
propertyParentExpression<Func<TParent, object>>Function(x) x.ParentProp
propertyChildExpression<Func<TChild, object>>Function(x) x.ChildProp
isInverseboolSpecify 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
parentTParentThe parent entity instance
propertyExpression<Func<TParent, object>>Function(x) x.PropName