This is a migrated thread and some comments may be shown as answers.

VirtualQueryableCollectionView DevForce

1 Answer 93 Views
Data Virtualization
This is a migrated thread and some comments may be shown as answers.
Sven J
Top achievements
Rank 2
Sven J asked on 25 Nov 2011, 02:51 PM
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);
       }
   }

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 30 Nov 2011, 08:10 AM
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 >>

Tags
Data Virtualization
Asked by
Sven J
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Share this question
or