InfernumDeus
InfernumDeus

Reputation: 1202

How to get maximum value of some property from all records in realm table?

Tried this but it doesn't work:

int maxValue = realm.All<myTable>().Max<myTable>().intProperty;

I'm getting error message:

System.NotSupportedException: The method 'Max' is not supported

Upvotes: 4

Views: 678

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726809

In LINQ you need to supply an expression selecting the property to Max() method:

int maxValue = realm.All<myTable>().Max(item => item.intProperty);

This may not work in LINQ 2 Entity, so use

int maxValue = realm
    .All<myTable>()
    .OrderByDescending(item => item.intProperty)
    .First().intProperty;

Upvotes: 4

Related Questions