Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
345
VirtualCollection Error When Paging
posted

I have a SL project.  I am using RIA service as my data layer.  I have a service class that makes the RIA service calls.  My view model contains the following methods below.  The grid loads fine on the initial load. Once I page, my 'LOESummmary_LoadCompleted' is called.  result.Entities throws an exception because none of the values are initialized because a Ria services call was not made for paging.  Most likely because the virtual collection is caching 300 records for me and my page size is only 100.  When paging should my callback get called.  Second what is the difference between the virtualcollection and DomainCollectionView by Microsoft?  Is my scenario supported with VirtualCollection?

View Model Code:

 private void InitializeCollection()
{
 _losSummaryPagedCollection = new VirtualCollection<DirectLOESummary>(300);
_losSummaryPagedCollection.PageSize = 100;
_losSummaryPagedCollection.ItemDataRequested += VirtualCollection_ItemDataRequested;
 }
private void VirtualCollection_ItemDataRequested(object sender, ItemDataRequestedEventArgs e)
{
 _dataService.LoadLOESummary(_criteria.Type.ToString(),
 _criteria.SearchIDCollection, 
_criteria.ActivityDate.Value, 
e.StartIndex, e.ItemsCount, 
LOESummmary_LoadCompleted, 
e.StartIndex); 
 }
 
private void LOESummmary_LoadCompleted(Ria.Common.ServiceLoadResult<DirectLOESummary> result)
 {
try
 {
 if (result.Error == null)
 {
if (_totalItemCount == 0)
 _totalItemCount = result.TotalEntityCount;
 LOSSummaryPagedCollection.AnticipatedCount = _totalItemCount;
_losSummaryPagedCollection.LoadItems((int)result.UserState, result.Entities);
NotifyPropertyChanged("LOSSummaryPagedCollection");
 }
else
{
Mediator.Instance.NotifyColleagues<Exception>("ShowError", result.Error);
 }
 }
catch (Exception ex)
 {
  Mediator.Instance.NotifyColleagues<Exception>("ShowError", ex);
 }
finally
{
 Mediator.Instance.NotifyColleagues<bool>("IsBusy"false);
 }
}

 

RIA Services Proxy:

public void LoadLOESummary(string idType, List<int> Id, DateTime ActivityDate,int startIndex, int total, Action<ServiceLoadResult<DirectLOESummary>> callback, object state)
        {
            var query = _context.LoadDirectLOESummariesQuery(idType, Id, ActivityDate);
            query.IncludeTotalCount = true;
            Load(query.Skip(startIndex).Take(total) , lo =>
            {
                callback(this.CreateResult(lo));
            }, state);
        }
ServiceLoadResult Class:
 public class ServiceLoadResult<T> : ServiceLoadResult where T : Entity
    {
        public ServiceLoadResult(IEnumerable<T> entities, object userState)
            : this(entities, entities.Count(), Enumerable.Empty<ValidationResult>(), nullfalse, userState)
        {
        }
 
        public ServiceLoadResult(
            IEnumerable<T> entities,
            int totalEntityCount,
            IEnumerable<ValidationResult> validationErrors,
            Exception error,
            bool cancelled,
            object userState)
            : base(entities, totalEntityCount, validationErrors, error, cancelled, userState)
        {
        }
 
        public new IEnumerable<T> Entities
        {
            get { return (IEnumerable<T>)base.Entities; }
        }
    }