public static Collections.VirtualList <TEntity> ToVirtualResultLazy <TEntity>(this Colosoft.Query.Queryable queryable, int pageSize = 0, string countExpression = null, string uiContext = null, Colosoft.Query.IQueryResultBindStrategy bindStrategy = null, Colosoft.Query.IQueryResultObjectCreator objectCreator = null) where TEntity : class
        {
            queryable.Require("queryable").NotNull();
            Collections.VirtualListLoader <TEntity>           virtualListLoader = null;
            Colosoft.Query.QueryableExecuterHandler <TEntity> executeSelect     = null;
            if (bindStrategy == null && objectCreator == null)
            {
                var ts = Colosoft.Query.TypeBindStrategyCache.GetItem(typeof(TEntity), t => new Colosoft.Query.QueryResultObjectCreator(t));
                objectCreator = ts;
                bindStrategy  = ts;
            }
            if (bindStrategy == null)
            {
                bindStrategy = new Colosoft.Query.TypeBindStrategy(typeof(TEntity), objectCreator);
            }
            var queryable2 = (Colosoft.Query.Queryable)queryable.Clone();

            if (typeof(Colosoft.Business.IEntity).IsAssignableFrom(typeof(TEntity)))
            {
                virtualListLoader = Colosoft.Business.EntityManager.Instance.GetEntityVirtualListLoader <TEntity>(queryable2, countExpression, true, uiContext, null);
                executeSelect     = (queryable3, dataSource, bindStrategy1, objectCreator1) => queryable3.ExecuteSelectProcessLazyResult <TEntity>(uiContext, null, bindStrategy1, objectCreator1);
            }
            else
            {
                virtualListLoader = new Colosoft.Business.QueryableVirtualListLoader <TEntity>(queryable2, countExpression, bindStrategy, objectCreator, null);
            }
            return(new Business.QueryableVirtualList <TEntity>(queryable2, pageSize, virtualListLoader, executeSelect, null, bindStrategy, objectCreator));
        }
        public static Collections.VirtualList <TProxy> ToProxyVirtualResult <TEntity, TProxy>(this Colosoft.Query.Queryable queryable, int pageSize = 0, string countExpression = null, Func <TEntity, TProxy> proxyCreator = null) where TEntity : new()
        {
            queryable.Require("queryable").NotNull();
            var queryable2    = (Colosoft.Query.Queryable)queryable.Clone();
            var bindStrategy  = Colosoft.Query.TypeBindStrategyCache.GetItem(typeof(TEntity), f => new Colosoft.Query.QueryResultObjectCreator(() => new TEntity()));
            var objectCreator = bindStrategy;

            return(new Business.QueryableVirtualList <TProxy>(queryable2, pageSize, new Colosoft.Business.QueryableVirtualListLoader <TProxy>(queryable2, countExpression, bindStrategy, bindStrategy, proxyCreator != null ? new Func <object, TProxy>(f => proxyCreator((TEntity)f)) : null), null, null, bindStrategy, objectCreator));
        }
        public static Collections.VirtualList <TEntity> ToVirtualResultLazy <TEntity>(this Colosoft.Query.Queryable queryable, int pageSize, Collections.VirtualListLoader <TEntity> listLoader, Colosoft.Query.IQueryResultBindStrategy bindStrategy = null, Colosoft.Query.IQueryResultObjectCreator objectCreator = null) where TEntity : class
        {
            queryable.Require("queryable").NotNull();
            var queryable2 = (Colosoft.Query.Queryable)queryable.Clone();

            Colosoft.Query.QueryableExecuterHandler <TEntity> executeSelect = null;
            if (typeof(Colosoft.Business.IEntity).IsAssignableFrom(typeof(TEntity)))
            {
                executeSelect = (queryable3, dataSource, bindStragety1, objectCreator1) => queryable3.ExecuteSelectProcessLazyResult <TEntity>(null, null, bindStragety1, objectCreator1);
            }
            return(new Business.QueryableVirtualList <TEntity>(queryable2, pageSize, listLoader, executeSelect, null, bindStrategy, objectCreator));
        }
        /// <summary>
        /// Método usado para recupera os dados para o preenchimento da lista virtual.
        /// </summary>
        /// <param name="virtualList"></param>
        /// <param name="startRow"></param>
        /// <param name="pageSize"></param>
        /// <param name="needItemsCount"></param>
        /// <param name="referenceObject"></param>
        /// <returns></returns>
        public override VirtualListLoaderResult <TEntity> Load(IObservableCollection virtualList, int startRow, int pageSize, bool needItemsCount, object referenceObject = null)
        {
            var countQuery = (Colosoft.Query.Queryable)_queryable.Clone();

            if (_countExpression != null)
            {
                countQuery.Count(_countExpression);
            }
            else
            {
                countQuery.Count();
            }
            countQuery.Sort = null;
            if (needItemsCount)
            {
                return(new VirtualListLoaderResult <TEntity>(null, ExecuteCount(countQuery)));
            }
            var sourceContext            = _queryable.SourceContext;
            var queryable2               = ((Colosoft.Query.Queryable)_queryable.Clone()).Skip(startRow).Take(pageSize);
            IEnumerable <IEntity> result = null;

            if (_isLazy)
            {
                result = _entityLoader.GetLazyEntities(queryable2.Execute(), sourceContext, _uiContext, _entityTypeManager);
            }
            else
            {
                var preparedQuery = Colosoft.Business.EntityManager.Instance.Prepare <TEntity>(queryable2, sourceContext, _uiContext);
                result = _entityLoader.GetFullEntities(preparedQuery, _queryable.SourceContext);
            }
            if (CastHandler != null)
            {
                result = result.Select(f => CastHandler(f));
            }
            return(new VirtualListLoaderResult <TEntity>(result.Select(f => (TEntity)f)));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Método usado para recupera os dados para o preenchimento da lista virtual.
        /// </summary>
        /// <param name="virtualList"></param>
        /// <param name="startRow"></param>
        /// <param name="pageSize"></param>
        /// <param name="needItemsCount"></param>
        /// <param name="referenceObject"></param>
        /// <returns></returns>
        public override VirtualListLoaderResult <T> Load(IObservableCollection virtualList, int startRow, int pageSize, bool needItemsCount, object referenceObject = null)
        {
            var countQuery = (Colosoft.Query.Queryable)_queryable.Clone();

            countQuery.NestedQueries.Clear();
            if (_countExpression != null)
            {
                countQuery = countQuery.Count(_countExpression);
            }
            else
            {
                countQuery = countQuery.Count();
            }
            countQuery.Sort = null;
            if (needItemsCount)
            {
                return(new VirtualListLoaderResult <T>(null, ExecuteCount(countQuery)));
            }
            var             multiQuery = _queryable.SourceContext.CreateMultiQuery();
            IEnumerable <T> result     = null;
            var             queryable2 = ((Colosoft.Query.Queryable)_queryable.Clone()).Skip(startRow).Take(pageSize);

            if (_bindStrategy == null && _objectCreator == null)
            {
                multiQuery.Add <T>(queryable2, (mq, q, r) => {
                    var items = new List <T>();
                    foreach (var i in r)
                    {
                        if (i is IConnectedEntity)
                        {
                            ((IConnectedEntity)i).Connect(mq.SourceContext);
                        }
                        items.Add(i);
                    }
                    result = items;
                });
            }
            else
            {
                multiQuery.Add(queryable2, (mq, q, r) => {
                    var items = new List <T>();
                    if (CastHandler == null)
                    {
                        foreach (var item in r)
                        {
                            if (item is IConnectedEntity)
                            {
                                ((IConnectedEntity)item).Connect(mq.SourceContext);
                            }
                            items.Add((T)item);
                        }
                    }
                    else
                    {
                        foreach (var item in r)
                        {
                            if (item is IConnectedEntity)
                            {
                                ((IConnectedEntity)item).Connect(mq.SourceContext);
                            }
                            items.Add(CastHandler(item));
                        }
                    }
                    result = items;
                }, _bindStrategy, _objectCreator);
            }
            multiQuery.Execute();
            return(new VirtualListLoaderResult <T>(result));
        }