Beispiel #1
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <T[]> LazyLoadInternal <T>(string[] ids, string[] includes, Action <T[]> onEval)
        {
            var multiLoadOperation = new MultiLoadOperation(this, DatabaseCommands.DisableAllCaching, ids);
            var lazyOp             = new LazyMultiLoadOperation <T>(multiLoadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval));
        }
Beispiel #2
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <Task <T[]> > LazyLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval, CancellationToken token = default(CancellationToken))
        {
            var multiLoadOperation = new MultiLoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, ids, includes);
            var lazyOp             = new LazyMultiLoadOperation <T>(multiLoadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval, token));
        }
        Lazy <TResult[]> ILazySessionOperations.Load <TTransformer, TResult>(string[] ids)
        {
            var transformer        = new TTransformer().TransformerName;
            var multiLoadOperation = new MultiLoadOperation(this, DatabaseCommands.DisableAllCaching, ids, null);
            var lazyOp             = new LazyMultiLoadOperation <TResult>(multiLoadOperation, ids, null, transformer);

            return(AddLazyOperation <TResult[]>(lazyOp, null));
        }
Beispiel #4
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <T[]> LazyLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval)
        {
            if (CheckIfIdAlreadyIncluded(ids, includes))
            {
                return(new Lazy <T[]>(() => ids.Select(Load <T>).ToArray()));
            }
            var multiLoadOperation = new MultiLoadOperation(this, DatabaseCommands.DisableAllCaching, ids, includes);
            var lazyOp             = new LazyMultiLoadOperation <T>(multiLoadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval));
        }
Beispiel #5
0
        public Lazy <Task <T[]> > LazyAsyncLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval, CancellationToken token = default(CancellationToken))
        {
            if (CheckIfIdAlreadyIncluded(ids, includes))
            {
                return(new Lazy <Task <T[]> >(async() => await Task.WhenAll(ids.Select(id => LoadAsync <T>(id, token)).ToArray()).WithCancellation(token)));
            }
            var multiLoadOperation = new MultiLoadOperation(this, AsyncDatabaseCommands.DisableAllCaching, ids, includes);
            var lazyOp             = new LazyMultiLoadOperation <T>(multiLoadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval));
        }
Beispiel #6
0
        /// <summary>
        /// Register to lazily load documents and include
        /// </summary>
        public Lazy <T[]> LazyLoadInternal <T>(string[] ids, KeyValuePair <string, Type>[] includes, Action <T[]> onEval)
        {
            var idsAndShards = ids.Select(id => new
            {
                id,
                shards = GetCommandsToOperateOn(new ShardRequestData
                {
                    Keys       = { id },
                    EntityType = typeof(T),
                })
            })
                               .GroupBy(x => x.shards, new DbCmdsListComparer());
            var cmds = idsAndShards.SelectMany(idAndShard => idAndShard.Key).Distinct().ToList();

            var multiLoadOperation = new MultiLoadOperation(this, () =>
            {
                var list = cmds.Select(cmd => cmd.DisableAllCaching()).ToList();
                return(new DisposableAction(() => list.ForEach(disposable => disposable.Dispose())));
            }, ids, includes);
            var lazyOp = new LazyMultiLoadOperation <T>(multiLoadOperation, ids, includes);

            return(AddLazyOperation(lazyOp, onEval, cmds));
        }