VirtualQueryableCollectionView DevForce

2 posts, 0 answers
  1. Sven J
    Sven J avatar
    26 posts
    Member since:
    Nov 2009

    Posted 25 Nov 2011 Link to this post

    Hi, 

    I'm trying to use the VirtualQueryableCollectionView to query data via DevForce/IdeaBlade. Unfortunately I'm facing a lot of problems. We use MVVM so my RadGridView binds to the VirtualQueryableCollectionView on my ViewModel. For better integration with DevForce I've inherited the collection and added some DevForce specific stuff.

    I want to sync grid data with DevForce's EntityManager Entites but adding and refreshing data doesn't work quite well with the VirtualQueryableCollectionView. Can someone give me a hint how I can handle that?

    Thanks,
    Sven

    Here is my class so far:
    public class EntityQueryableCollectionView<T> : VirtualQueryableCollectionView where T : Entity
       {
           public IEntityQuery<T> Query { get; set; }
           public IEntityQuery<T> BaseQuery { get { return (EntityQuery<T>)Query.Where(FilterDescriptors); } }
           public Expression<Func<T, object>> InitialOrderBy { get; set; }
           public ListSortDirection InitialOrderByDirection { get; set; }
     
           public EntityQueryableCollectionView(IEntityQuery<T> query, Expression<Func<T, object>> orderBy, ListSortDirection direction = ListSortDirection.Ascending)
               : base()
           {
               Query = query;
               InitialOrderBy = orderBy;
               InitialOrderByDirection = direction;
     
               LoadSize = 20;
     
               ItemsLoading += (s, e) => LoadData(e.StartIndex, e.ItemCount);
               FilterDescriptors.CollectionChanged += (s, e) => CountRecords();
               FilterDescriptors.ItemChanged += (s, e) => CountRecords();
     
               CountRecords();
           }
     
           public void CountRecords()
           {
               var countQuery = BaseQuery
                   .AsScalarAsync()
                   .Count();
               countQuery.Completed += (sender, args) => VirtualItemCount = args.Result;
           }
     
           public void LoadData(int startIndex, int itemCount)
           {
               var baseQuery = (EntityQuery<T>)Query
                   .Where(FilterDescriptors);
     
               // Skip needs an order
               if (SortDescriptors.Count == 0)
                   SortDescriptions.Add(new SortDescription(InitialOrderBy.AsString(), InitialOrderByDirection));
     
               var resultQuery = (EntityQuery<T>)baseQuery
                   .Sort(SortDescriptors)
                   .Skip(startIndex).Take(itemCount);
     
               resultQuery.QueryStrategy = new QueryStrategy(FetchStrategy.DataSourceAndCache, MergeStrategy.PreserveChanges);
     
               resultQuery.ExecuteAsync().Completed += (s, e) =>
                   Load(startIndex, e.Results.Where(entity => entity.EntityAspect.EntityState.InList(EntityState.Added, EntityState.Modified, EntityState.Unchanged)));
           }
     
           public new int Add(object item)
           {
               Query.EntityManager.AddEntity(item);
               var pos = base.Add(item);
               Refresh();
               MoveCurrentTo(item);
               return pos;
           }
     
           public override void Remove(object item)
           {
               MoveCurrentToNext();
               (item as Entity).EntityAspect.Delete();
               base.Remove(item);
           }
       }
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 30 Nov 2011 Link to this post

    Hi,

     Currently the virtual collection can be used mostly for read-only scenarios. Please add/remove items in your original context and reload the virtual collection if/when needed. 

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
Back to Top