Q:

Using conditional clause in IFindFluent .SortBy block

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?

A:

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.

