Exemplo n.º 1
0
 internal static IQueryable <TEntity> Paged <TEntity>(this IQueryable <TEntity> source, int itemId, bool isPrev, int count = 0)
     where TEntity : class, IListItemEntity, new()
 {
     Check.NotNull(source, nameof(source));
     if (source is SpEntityQueryable <TEntity, ISpEntryDataContext> )
     {
         var executor = (source as SpEntityQueryable <TEntity, ISpEntryDataContext>).GetExecutor();
         if (executor != null)
         {
             var args     = (SpQueryArgs <ISpEntryDataContext>)executor.SpQueryArgs.Clone();
             var lastItem = itemId > 0 ? source.Where(item => item.Id == itemId).FirstListItem() : null;
             if (lastItem != null)
             {
                 args.IsPaged     = true;
                 args.IsPagedPrev = isPrev;
                 var expression = new PagedExpression <ISpEntryDataContext>(source.Expression, args, lastItem, false);
                 var provider   = new SpEntityQueryable <TEntity>(args).Provider;
                 source = new SpEntityQueryable <TEntity>(provider, source.Expression).Concat(new SpEntityQueryable <TEntity>(provider, expression));
                 if (count > 0)
                 {
                     source = source.Take(count);
                 }
             }
             else
             {
                 source = Enumerable.Empty <TEntity>().AsQueryable();
             }
         }
     }
     return(source);
 }
Exemplo n.º 2
0
 public static IQueryable <TEntity> Previous <TEntity>(this IQueryable <TEntity> source, int count = 0)
     where TEntity : class, IListItemEntity, new()
 {
     Check.NotNull(source, nameof(source));
     if (source is SpEntityQueryable <TEntity, ISpEntryDataContext> )
     {
         var executor = (source as SpEntityQueryable <TEntity, ISpEntryDataContext>).GetExecutor();
         if (executor != null)
         {
             var args      = (SpQueryArgs <ISpEntryDataContext>)executor.SpQueryArgs.Clone();
             var firstItem = args.IsPaged && args.IsPagedPrev ? source.ToListItems().FirstOrDefault() : source.FirstListItem();
             if (firstItem != null)
             {
                 args.IsPaged     = true;
                 args.IsPagedPrev = true;
                 var expression = new PagedExpression <ISpEntryDataContext>(source.Expression, args, firstItem, true);
                 var provider   = new SpEntityQueryable <TEntity>(args).Provider;
                 source = new SpEntityQueryable <TEntity>(provider, source.Expression).Concat(new SpEntityQueryable <TEntity>(provider, expression));
                 if (count > 0)
                 {
                     source = source.Take(count);
                 }
             }
         }
     }
     return(source);
 }
Exemplo n.º 3
0
 public virtual void VisitPagedClause(PagedExpression <TContext /*, TEntity*/> expression, QueryModel queryModel)
 {
     if (_args != null && _spView != null)
     {
         var visitor = new PagedExpressionVisitor <TContext, TEntity>(_args, expression, _spView);
         visitor.VisitQueryModel(queryModel);
         _args.PagingInfo = visitor.PagingInfo;
         _args.IsPaged    = true;
     }
 }
Exemplo n.º 4
0
 public PagedExpressionVisitor(SpQueryArgs <TContext> args, PagedExpression <TContext /*, TEntity*/> expression, Caml.View spView) : base(args, null)
 {
     _args       = args;
     _expression = expression;
     _spView     = spView;
 }