1

I'm trying to apply a conditional SortBy to a find as follows:

var findFluent = Collection.Find (...)
    .SortBy (record => record.IsActive)
    .SortBy (record => record.Client != null
      ? record.Client.Profile.FirstName 
      : record.Profile.FirstName);

However, I'm receiving the following error:

"Unable to determine the serialization information for record => IIF((record.Client != null), record.Client.Profile.FirstName, record.Profile.FirstName)."

Do I have to add/implement IBsonDocumentSerializer on one of the classes in question or is this operation not possible?

Graeme
  • 773
  • 1
  • 8
  • 18

1 Answers1

1

I ended up simply adding a new .SortBy () clause based on the logic in the conditional:

var findFluent = Collection.Find (...)
   .SortBy (record => record.IsActive)
   .SortBy (record => record.Client.Profile.FirstName) 
   .SortBy (record => record.Profile.FirstName);

The driver seems to ignore the sort if a value is null or cannot be evaluated.

Graeme
  • 773
  • 1
  • 8
  • 18