Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        public DataStreamer(FileEntity parent)
        {
            this.parent = parent;
            parentType  = parent.GetType();

            db = TypeMap.GetDatabase(parentType);

            chunkCollection = db.GetCollection <FileChunk>(DB.CollectionName <FileChunk>());

            var dbName = db.DatabaseNamespace.DatabaseName;

            if (!indexedDBs.Contains(dbName))
            {
                indexedDBs.Add(dbName);

                _ = chunkCollection.Indexes.CreateOneAsync(
                    new CreateIndexModel <FileChunk>(
                        Builders <FileChunk> .IndexKeys.Ascending(c => c.FileID),
                        new CreateIndexOptions {
                    Background = true, Name = $"{nameof(FileChunk.FileID)}(Asc)"
                }));
            }
        }
Пример #4
0
 /// <summary>
 /// Gets the collection name for this entity
 /// </summary>
 public static string CollectionName <T>(this T _) where T : IEntity
 {
     return(DB.CollectionName <T>());
 }