Basically I'm trying to retrieve a list of objects from my database (using Entity Framework 6), however I want the items to be ordered in a certain way.
I have tried the following:
context.Coordinates.OrderBy(x =>
{
double latDif = Math.Abs(centerLat - x.Longtitude);
double lngDif = Math.Abs(centerLng - x.Latitude);
double dif = latDif + lngDif;
return dif;
});
However, the compiler shows the following error:
A lambda expression with a statement body cannot be converted to an expression tree
I have looked this up and understand that I can't use a statement body (the curly brackets) when calling orderby in linq-to-sql.
However how can I then do a complex orderby like the one above, without loading all the entries?
By the way, in case you are wondering I'm trying to order the items by those which are closest to the center coords (centerLat and centerLng).