How to reorder an embedded Array and store it

Is it possible to reorder an embedded Array on a managed RealmObject.
For example we have the two classes:

public class Outer: RealmObject{
public IList<Inner> EmbeddedList {set;}
}
public class Inner: EmbeddedObject{
public int Number {get;set;}
}

and want to do something like : Outer.EmbeddedList.OrderBy(t=>t.number);

Additional Context: Of Course i can access the list orderd but the goal is to store the list orderd.
The list is bound to a CollectionView in Xamarin Forms so accessing the List by a seperat property like

public class Outer: RealmObject{
public IList<Inner> EmbeddedList {set;}
public IList<Inner> EmbeddedOrdered => EmbeddedList.OrderBy(t=> t.number);
}

is not really a good solution because crud operations will not be seen in the ui, as PropertyChanged will not be fired for the EmbeddedOrdered Property.
Thanks for any help in advance

Hi @Jannis_N_A, welcome to the forum :slight_smile:

Actually you don’t need to add them in order beforehand. You need to do something like:

public IList<Inner> EmbeddedOrdered => EmbeddedList.AsRealmQueryable().OrderBy(t=> t.number);

This will make EmbeddedList behave as a regular query, including emitting notifications when an element is added, that is what you need.

1 Like

Hi @papafe,
thank you very much this is very helpful. I will try it out :smiley:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.