Hi All,
We use MongoDB as our application database integrated through .NET Core 6.0.The C# driver version is 2.19.0.
We are facing an issue with sorting where we need to sort by a field and put a specific value on top.
We have a C# class which is as follows.
public class CaseShortInfo
{
public IList<AdditionalAttributesNst> AdditionalData { get; set; } = new
List<AdditionalAttributesNst>();
public string BatchNumber { get; set; }
public string CaseName { get; set; }
public string CaseNumber { get; set; }
public string CaseOriginName { get; set; }
public IList<CountryEntity> CountryList { get; set; } = new List<CountryEntity>();
public bool External { get; set; }
public IList<IdNameNst> GeneralIndicators { get; set; } = new List<IdNameNst>();
public string Id { get; set; }
public IList<IdNameNst> IdentificationResult { get; set; } = new List<IdNameNst>();
public IList<IdNameNst> Indicators { get; set; } = new List<IdNameNst>();
public int? OrderNo { get; set; }
public string PrimaryPartyName { get; set; }
public string ProductId { get; set; }
public string ProductNumber { get; set; }
public int Quantity { get; set; }
public int? QuantitySeized { get; set; }
public IList<string> Tags { get; set; } = new List<string>();
}
We have a function which returns IMongoQueryable
var queryable = await GetCaseShortInfoQueryable();
We want to sort it so that values matching a specific product are arranged at the top with this LINQ query.
queryable = queryable.OrderByDescending(x => x.ProductId == "1234").ThenBy(x => x.productId);
But somehow the objects with Product Id 1234 are grouped together but get listed in between and never get listed at the top.
When we try the same with any C# IQueryable, it works fine.
So would like to know the reason for this behavior.
Thanks in advance