Ejemplo n.º 1
0
 /// <summary>
 /// Persists an entity to MongoDB
 /// </summary>
 /// <typeparam name="T">Any class that implements IEntity</typeparam>
 /// <param name="entity">The instance to persist</param>
 /// <param name="session">An optional session if using within a transaction</param>
 public ReplaceOneResult Save <T>(T entity, IClientSessionHandle session = null, bool _ = false) where T : IEntity
 {
     return(Run.Sync(() => DB.SaveAsync(entity, session)));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Persists multiple entities to MongoDB in a single bulk operation
 /// </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>
 public BulkWriteResult <T> Save <T>(IEnumerable <T> entities, IClientSessionHandle session = null, bool _ = false) where T : IEntity
 {
     return(Run.Sync(() => DB.SaveAsync(entities, session)));
 }
Ejemplo n.º 3
0
 public Task SaveAsync<T>(IEnumerable<T> entities) where T : IEntity
 {
     return DB.SaveAsync(entities, Session, db);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Saves an entity while preserving some property values in the database.
 /// The properties to be preserved can be specified with a 'New' expression or using the [Preserve] or [DontPreserve] attributes.
 /// <para>TIP: The 'New' expression should specify only root level properties.</para>
 /// </summary>
 /// <typeparam name="T">Any class that implements IEntity</typeparam>
 /// <param name="entity">The entity to save</param>
 /// <param name="preservation">x => new { x.PropOne, x.PropTwo }</param>
 /// <param name="session">An optional session if using within a transaction</param>
 public UpdateResult SavePreserving <T>(T entity, Expression <Func <T, object> > preservation = null, IClientSessionHandle session = null, bool _ = false) where T : IEntity
 {
     return(Run.Sync(() => DB.SavePreservingAsync(entity, preservation, session)));
 }
Ejemplo n.º 5
0
 public IAggregateFluent<T> GeoNear<T>(Coordinates2D NearCoordinates, Expression<Func<T, object>> DistanceField, bool Spherical = true, int? MaxDistance = null, int? MinDistance = null, int? Limit = null, BsonDocument Query = null, int? DistanceMultiplier = null, Expression<Func<T, object>> IncludeLocations = null, string IndexKey = null, AggregateOptions options = null) where T : IEntity
 {
     return DB.FluentGeoNear(NearCoordinates, DistanceField, Spherical, MaxDistance, MinDistance, Limit, Query, DistanceMultiplier, IncludeLocations, IndexKey, options, Session, db);
 }
Ejemplo n.º 6
0
 public Task SaveAsync<T>(T entity) where T : IEntity
 {
     return DB.SaveAsync(entity, Session, db);
 }
Ejemplo n.º 7
0
 public IAggregateFluent<T> FluentTextSearch<T>(Search searchType, string searchTerm, bool caseSensitive = false, bool diacriticSensitive = false, string language = null, AggregateOptions options = null)
 {
     return DB.FluentTextSearch<T>(searchType, searchTerm, caseSensitive, diacriticSensitive, language, options, Session, db);
 }
Ejemplo n.º 8
0
 public IAggregateFluent<T> Fluent<T>(AggregateOptions options = null)
 {
     return DB.Fluent<T>(options, Session, db);
 }
Ejemplo n.º 9
0
 public Task DeleteAsync<T>(Expression<Func<T, bool>> expression) where T : IEntity
 {
     return DB.DeleteAsync(expression, Session, db);
 }
Ejemplo n.º 10
0
 public Task DeleteAsync<T>(IEnumerable<string> IDs) where T : IEntity
 {
     return DB.DeleteAsync<T>(IDs, Session, db);
 }
Ejemplo n.º 11
0
 public Task DeleteAsync<T>(string ID) where T : IEntity
 {
     return DB.DeleteAsync<T>(ID, Session, db);
 }
Ejemplo n.º 12
0
        private void Init <TParent>(TParent parent, string propertyParent, string propertyChild, bool isInverse) where TParent : IEntity
        {
            this.parent    = parent;
            this.isInverse = isInverse;

            if (this.isInverse)
            {
                JoinCollection = DB.GetRefCollection <TParent>($"[({propertyParent}){DB.CollectionName<TChild>()}~{DB.CollectionName<TParent>()}({propertyChild})]");
            }
            else
            {
                JoinCollection = DB.GetRefCollection <TParent>($"[({propertyChild}){DB.CollectionName<TParent>()}~{DB.CollectionName<TChild>()}({propertyParent})]");
            }

            CreateIndexesAsync(JoinCollection);
        }
Ejemplo n.º 13
0
        private void Init <TParent>(TParent parent, string property) where TParent : IEntity
        {
            if (DB.DatabaseName <TParent>() != DB.DatabaseName <TChild>())
            {
                throw new NotSupportedException("Cross database relationships are not supported!");
            }

            this.parent    = parent;
            isInverse      = false;
            JoinCollection = DB.GetRefCollection <TParent>($"[{DB.CollectionName<TParent>()}~{DB.CollectionName<TChild>()}({property})]");
            CreateIndexesAsync(JoinCollection);
        }
 /// <summary>
 /// Deletes the collection of a given entity type as well as the join collections for that entity.
 /// <para>TIP: When deleting a collection, all relationships associated with that entity type is also deleted.</para>
 /// </summary>
 /// <typeparam name="T">The entity type to drop the collection of</typeparam>
 public Task DropCollectionAsync <T>() where T : IEntity
 {
     return(DB.DropCollectionAsync <T>(Session));
 }
 /// <summary>
 /// Creates a collection for an Entity type explicitly using the given options
 /// </summary>
 /// <typeparam name="T">The type of entity that will be stored in the created collection</typeparam>
 /// <param name="options">The options to use for collection creation</param>
 /// <param name="cancellation">An optional cancellation token</param>
 public Task CreateCollectionAsync <T>(Action <CreateCollectionOptions <T> > options, CancellationToken cancellation = default) where T : IEntity
 {
     return(DB.CreateCollectionAsync(options, cancellation, Session));
 }