im using the MongoDB C# Driver and wanna use filtering by expression and Sorting by fieldname.
Thats my implementation:
List<OBJECT> result = collection.FindAll().SetSortOrder(SortFieldName).AsQueryable().Where(expression).ToList();
variable expression is:
Expression<Func<OBJECT, bool>> expression
and SortFieldName is a string which contains “Name” or something.
This command does’nt work, because the result is null. What do I wrong?
You can’t mix native MongoDB queries with LINQ queries. You must write your query either entirely in one way or the other. Here’s some sample code showing both ways of writing the same query: