realm / realm-dotnet

Realm is a mobile database: a replacement for SQLite & ORMs
https://realm.io
Apache License 2.0
1.24k stars 161 forks source link

LINQ GroupBy() support #1150

Open brittonbeckham opened 7 years ago

brittonbeckham commented 7 years ago

Goal

Have Realm add support for LINQ's GroupBy() and Select() operations.

Expected Results

To work in the same manner as the .Where() results of a realm collection. This would allow for live updating. I'm currently developing a cross-platform app in Xamarin. I am using a lot of ListView controls in my pages. One of the easiest ways to get a ListView to group things in the MVVM patter is by using a GroupBy method of an object collection.

Note: I am aware of the LINQ support page, but am extremely interested in this and would like to know when this could be available or not.

nirinchev commented 7 years ago

Unfortunately, our core's query engine does not yet support that. Here's the issue for GroupBy: https://github.com/realm/realm-core/issues/1073

Similarly, projections are also not supported: https://github.com/realm/realm-core/issues/1037

Once those land, we'll make them available in the .NET. Unfortunately, we can't commit to a timeframe for those, but your (and other users' interest) will surely be taken into account when planning our resources.

In the meantime, you could materialize the query by calling .ToArray() and apply the grouping/projection on that. Keep in mind that, because RealmObjects are "live", this will not introduce significant overhead (i.e. we won't load any data in memory - just pointers to the objects). Unfortunately, with that approach you'll lose notifications for collection changes, so if you need those, you'll have to apply a workaround in order to notify the UI of any changes.

brittonbeckham commented 7 years ago

Thanks for the reply. I'm sure many will be looking forward to using the support in the future once it's available.

I went ahead and converted my ListView source query to just materialize the results. Before I materialized it I added a SubscribeForNotifications() on the query so that I could at least still get real-time view model updates. This works fine for now. Loving Realm so far.