/// <summary> /// Get an IAggregateFluent of parents matching multiple child IDs for this relationship. /// </summary> /// <typeparam name="TParent">The type of the parent IEntity</typeparam> /// <param name="childIDs">An IEnumerable of child IDs</param> /// <param name="session">An optional session if using within a transaction</param> /// <param name="options">An optional AggregateOptions object</param> public IAggregateFluent <TParent> ParentsFluent <TParent>(IEnumerable <string> childIDs, IClientSessionHandle session = null, AggregateOptions options = null) where TParent : IEntity { if (typeof(TParent) == typeof(TChild)) { throw new InvalidOperationException("Both parent and child types cannot be the same"); } if (inverse) { return(JoinFluent(session, options) .Match(f => f.In(j => j.ParentID, childIDs)) .Lookup <JoinRecord, TParent, Joined <TParent> >( DB.Collection <TParent>(db), j => j.ChildID, p => p.ID, j => j.Results) .ReplaceRoot(j => j.Results[0]) .Distinct()); } else { return(JoinFluent(session, options) .Match(f => f.In(j => j.ChildID, childIDs)) .Lookup <JoinRecord, TParent, Joined <TParent> >( DB.Collection <TParent>(db), r => r.ParentID, p => p.ID, j => j.Results) .ReplaceRoot(j => j.Results[0]) .Distinct()); } }
protected virtual Task CallMethodAsync(IClientSessionHandle session, CancellationToken cancellationToken) { throw new NotSupportedException(); }
public Task <DeleteResult> DeleteOneAsync(IClientSessionHandle session, FilterDefinition <SitePage> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
private static Task <UpdateResult> SavePartial <T>(T entity, Expression <Func <T, object> > members, IClientSessionHandle session, CancellationToken cancellation, bool excludeMode = false) where T : IEntity { PrepAndCheckIfInsert(entity); //just prep. we don't care about inserts here return (session == null ? Collection <T>().UpdateOneAsync(e => e.ID == entity.ID, Builders <T> .Update.Combine(BuildUpdateDefs(entity, members, excludeMode)), updateOptions, cancellation) : Collection <T>().UpdateOneAsync(session, e => e.ID == entity.ID, Builders <T> .Update.Combine(BuildUpdateDefs(entity, members, excludeMode)), updateOptions, cancellation)); }
/// <summary> /// Saves a batch of complete entities replacing existing ones or creating new ones if they do not exist. /// If ID value is null, a new entity is created. If ID has a value, then existing entity is replaced. /// </summary> /// <typeparam name="T">Any class that implements IEntity</typeparam> /// <param name="entities">The entities to persist</param> /// <param name="session">An optional session if using within a transaction</param> /// <param name="cancellation">And optional cancellation token</param> public static Task <BulkWriteResult <T> > SaveAsync <T>(IEnumerable <T> entities, IClientSessionHandle session = null, CancellationToken cancellation = default) where T : IEntity { var models = new List <WriteModel <T> >(entities.Count()); foreach (var ent in entities) { WriteModel <T> model; if (PrepAndCheckIfInsert(ent)) { model = new InsertOneModel <T>(ent); } else { model = new ReplaceOneModel <T>( filter: Builders <T> .Filter.Eq(e => e.ID, ent.ID), replacement: ent) { IsUpsert = true }; } models.Add(model); } return(session == null ? Collection <T>().BulkWriteAsync(models, unOrdBlkOpts, cancellation) : Collection <T>().BulkWriteAsync(session, models, unOrdBlkOpts, cancellation)); }
public override Task <IAsyncCursor <TResult> > MapReduceAsync <TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions <TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken)) { options = options ?? new MapReduceOptions <TDocument, TResult>(); options.Filter = CombineFilters(options.Filter); return(_wrappedCollection.MapReduceAsync(session, map, reduce, options, cancellationToken)); }
public BussinesController(IRepositoryUser repositoryUser, IRepositoryAuthor repositoryAuthor, IClientSessionHandle clientSessionHandle) => (_repositoryUser, _repositoryAuthor, _clientSessionHandle) = (repositoryUser, repositoryAuthor, clientSessionHandle);
/// <summary> /// Removes a child reference by ID. /// </summary> /// <param name="childID">The ID of the child entity to remove the reference of.</param> /// <param name="session">An optional session if using within a transaction</param> public void Remove(string childID, IClientSessionHandle session = null) { Run.Sync(() => RemoveAsync(childID, session)); }
/// <summary> /// Removes a child reference. /// </summary> /// <param name="child">The child IEntity to remove the reference of.</param> /// <param name="session">An optional session if using within a transaction</param> public Task RemoveAsync(TChild child, IClientSessionHandle session = null) { return(RemoveAsync(child.ID, session)); }
/// <summary> /// An IAggregateFluent of JoinRecords for this relationship /// </summary> /// <param name="options">An optional AggregateOptions object</param> /// <param name="session">An optional session if using within a transaction</param> public IAggregateFluent <JoinRecord> JoinFluent(IClientSessionHandle session = null, AggregateOptions options = null) { return(session == null ? JoinCollection.Aggregate(options) : JoinCollection.Aggregate(session, options)); }
/// <summary> /// Removes a child reference. /// </summary> /// <param name="child">The child IEntity to remove the reference of.</param> /// <param name="session">An optional session if using within a transaction</param> public void Remove(TChild child, IClientSessionHandle session = null) { Run.Sync(() => RemoveAsync(child, session)); }
/// <summary> /// Adds a new child reference by ID. /// </summary> /// <param name="childID">The ID of the child entity to add.</param> /// <param name="session">An optional session if using within a transaction</param> public void Add(string childID, IClientSessionHandle session = null) { Run.Sync(() => AddAsync(childID, session)); }
/// <summary> /// Adds a new child reference. /// <para>WARNING: Make sure to save the parent and child Entities before calling this method.</para> /// </summary> /// <param name="child">The child Entity to add.</param> /// <param name="session">An optional session if using within a transaction</param> public void Add(TChild child, IClientSessionHandle session = null) { Run.Sync(() => AddAsync(child, session)); }
/// <summary> /// Get the number of children for a relationship /// </summary> /// <param name="session">An optional session if using within a transaction</param> /// <param name="options">An optional AggregateOptions object</param> public long ChildrenCount(IClientSessionHandle session = null, CountOptions options = null) { return(Run.Sync(() => ChildrenCountAsync(session, options))); }
public override TProjection FindOneAndReplace <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.FindOneAndReplace(session, CombineFilters(filter), replacement, options, cancellationToken)); }
public UnifiedAssertSessionNotDirtyOperation(IClientSessionHandle session) { _session = session; }
public override Task <TProjection> FindOneAndUpdateAsync <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.FindOneAndUpdateAsync(session, CombineFilters(filter), update, options, cancellationToken)); }
internal UpdateAndGet(IClientSessionHandle session = null, string db = null) : base(session, db) { }
public override Task <IAsyncCursor <TResult> > AggregateAsync <TResult>(IClientSessionHandle session, PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { var filteredPipeline = CreateFilteredPipeline(pipeline); return(_wrappedCollection.AggregateAsync(session, filteredPipeline, options, cancellationToken)); }
public override void AggregateToCollection <TResult>(IClientSessionHandle session, PipelineDefinition <TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { var filteredPipeline = CreateFilteredPipeline(pipeline); _wrappedCollection.AggregateToCollection(session, filteredPipeline, options, cancellationToken); }
/// <summary> /// Saves a batch of entities partially excluding the specified subset of properties. /// If ID value is null, a new entity is created. If ID has a value, then existing entity is updated. /// <para>TIP: The properties to be excluded can be specified with a 'New' expression. /// You can only specify root level properties with the expression.</para> /// </summary> /// <typeparam name="T">Any class that implements IEntity</typeparam> /// <param name="entities">The batch of entities to save</param> /// <param name="members">x => new { x.PropOne, x.PropTwo }</param> /// <param name="session">An optional session if using within a transaction</param> /// <param name="cancellation">An optional cancellation token</param> public static Task <BulkWriteResult <T> > SaveExceptAsync <T>(IEnumerable <T> entities, Expression <Func <T, object> > members, IClientSessionHandle session = null, CancellationToken cancellation = default) where T : IEntity { return(SavePartial(entities, members, session, cancellation, true)); }
public override Task <BulkWriteResult <TDocument> > BulkWriteAsync(IClientSessionHandle session, IEnumerable <WriteModel <TDocument> > requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.BulkWriteAsync(session, CombineModelFilters(requests), options, cancellationToken)); }
private static Task <BulkWriteResult <T> > SavePartial <T>(IEnumerable <T> entities, Expression <Func <T, object> > members, IClientSessionHandle session, CancellationToken cancellation, bool excludeMode = false) where T : IEntity { var models = new List <WriteModel <T> >(entities.Count()); foreach (var ent in entities) { PrepAndCheckIfInsert(ent); //just prep. we don't care about inserts here models.Add( new UpdateOneModel <T>( filter: Builders <T> .Filter.Eq(e => e.ID, ent.ID), update: Builders <T> .Update.Combine(BuildUpdateDefs(ent, members, excludeMode))) { IsUpsert = true }); } return(session == null ? Collection <T>().BulkWriteAsync(models, unOrdBlkOpts, cancellation) : Collection <T>().BulkWriteAsync(session, models, unOrdBlkOpts, cancellation)); }
public override Task <long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition <TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.CountDocumentsAsync(session, CombineFilters(filter), options, cancellationToken)); }
/// <summary> /// Saves an entity partially with only the specified subset of properties. /// If ID value is null, a new entity is created. If ID has a value, then existing entity is updated. /// <para>TIP: The properties to be saved can be specified with a 'New' expression. /// You can only specify root level properties with the expression.</para> /// </summary> /// <typeparam name="T">Any class that implements IEntity</typeparam> /// <param name="entity">The entity to save</param> /// <param name="members">x => new { x.PropOne, x.PropTwo }</param> /// <param name="session">An optional session if using within a transaction</param> /// <param name="cancellation">An optional cancellation token</param> public static Task <UpdateResult> SaveOnlyAsync <T>(T entity, Expression <Func <T, object> > members, IClientSessionHandle session = null, CancellationToken cancellation = default) where T : IEntity { return(SavePartial(entity, members, session, cancellation)); }
public override Task <IAsyncCursor <TField> > DistinctAsync <TField>(IClientSessionHandle session, FieldDefinition <TDocument, TField> field, FilterDefinition <TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.DistinctAsync(session, field, CombineFilters(filter), options, cancellationToken)); }
public Task <long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition <SitePage> filter, CountOptions options = null, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
public override Task <IAsyncCursor <TProjection> > FindAsync <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, FindOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken)) { return(_wrappedCollection.FindAsync(session, CombineFilters(filter), options, cancellationToken)); }
public IAsyncCursor <TField> Distinct <TField>(IClientSessionHandle session, FieldDefinition <SitePage, TField> field, FilterDefinition <SitePage> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { throw new NotImplementedException(); }
/// <summary> /// Get an IAggregateFluent of parents matching a single child ID for this relationship. /// </summary> /// <typeparam name="TParent">The type of the parent IEntity</typeparam> /// <param name="childID">An child ID</param> /// <param name="session">An optional session if using within a transaction</param> public IAggregateFluent <TParent> ParentsFluent <TParent>(string childID, IClientSessionHandle session = null) where TParent : IEntity { return(ParentsFluent <TParent>(new[] { childID }, session)); }