Fetch new rows - Azure Mobile Services

208 views Asked by At

I want my MobileServiceIncrementalLoadingCollection<Video, Video> Videos; (which is bound to a ListView) to be updated every 5 seconds with the new rows from my Azure Database, if any.

Page Load

Videos = VideoTable.ThenByDescending(x => x.DateTime).ToIncrementalLoadingCollection();

At that phase the Videos collection has the first items loaded (as it's an incremental loading collection), and visible in the ListView.

After that, every 5 seconds I am executing the following code (which is not working/adding the new rows in the collection)

var tempVideos = VideoTable.ThenByDescending(x => x.DateTime).ToIncrementalLoadingCollection();
var newVideos = tempVideos.Where(x => !Videos.Contains(x, new VideoComparer()));            
foreach (Video v in newVideos)
{
    Videos.Insert(0, v);

}

I don't want to use Videos = tempVideos because the whole ListView is updating and AddDeleteThemeTransition is shown for every item every 5 seconds which is really annoying and ugly.

So my question is,

How can I add the newly added table rows in a MobileServiceIncrementalLoadingCollection after the creation of the collection without recreating the collection?



PS. I am using .NET Backend if that matters.

1

There are 1 answers

2
NER1808 On

It sounds like you want

1) to add new items to your collection, but only if they did not exist in the database in the initial call. 2) view a sorted collection

In answer:

1) This is not really the point of ToIncrementalLoadingCollection(), which is more suited to pagination or load on scroll type action. For this the control will automatically call LoadMoreItemsAsync() when required.

It sounds like you want to load all records and then update the collection with new ones. You will need to implement a query that can identify the new ones in your database and just add them to your collection.

2) As, I assume, you are using an ObservableCollection with ISupportIncrementalLoading then the trick is to sort and filter the view rather than the collection. This means you are not that concerned about the order in which items are added to the ObservableCollection. On your view you should implement a CollectionViewSource resource bound to your ObservableCollection in the XAML.