Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:54:21+00:00 2026-06-18T00:54:21+00:00

im using the MongoDB C# Driver and wanna use filtering by expression and Sorting

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:54:22+00:00Added an answer on June 18, 2026 at 12:54 am

    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:

    collection.Insert(new C { Id = 1, X = 3 });
    collection.Insert(new C { Id = 2, X = 2 });
    collection.Insert(new C { Id = 3, X = 1 });
    
    Console.WriteLine("Using MongoDB query:");
    foreach (var document in collection.Find(Query.GT("X", 1)).SetSortOrder("X"))
    {
        Console.WriteLine(document.X);
    }
    Console.WriteLine();
    
    Console.WriteLine("Using LINQ:");
    foreach (var document in collection.AsQueryable().Where(c => c.X > 1).OrderBy(c => c.X))
    {
        Console.WriteLine(document.X);
    }
    Console.WriteLine();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using the npm mongodb driver with node. I have collection.findOne({query}, function(err, result) {
I am using node-mongodb-native driver. I tried collection.findOne({email: 'a@mail.com'}, function(err, result) { if (!result)
I am using the java MongoDB driver for gridfs and would like to use
I'm using the node-mongodb-native driver with connect-session-mongo . When I use connect-session-mongo with the
Using the C# MongoDB driver, we currently create our collection like so: MongoServer mongoServer
Using MongoDB C# driver ( http://github.com/samus/mongodb-csharp ), seems that I'm unable to get the
I am using MongoDB v1.4 and the mongodb-csharp driver and I try to group
I have setup hadoop on top of mongodb using hadoop-mongodb driver. Currently I can
I'm using the JavaScript mongodb driver from nodejs. I want to do this query
I'm inserting documents using node mongodb native driver into a mongodb (sic!). My objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.