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 8679565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:00:13+00:00 2026-06-12T21:00:13+00:00

First, I’m grabbing ClientID. Then, I get all Invoices associated with that ClientID. I

  • 0

First, I’m grabbing ClientID. Then, I get all Invoices associated with that ClientID. I want to return data all ordered by InvoiceNumber, descending. Here’s my code:

var rvInvoices =
             (from i in db.QB_INVOICES_HEADER
                where i.ClientID == cId
                select i).ToList();
foreach (var itm in rvInvoices)
{
        InvoiceModel cm = new InvoiceModel()
        {
                InvoiceNumber = itm.InvoiceNumber,
                InvoiceSentDt = itm.InvoiceSentDt,
                InvoiceDt = itm.InvoiceDt,
                Amount = itm.Amount,
                Term = itm.Term,
                ClientName = itm.CI_CLIENTLIST.ClientName
        };

        listInvoices.Add(cm);
}

return listInvoices;
  • 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-12T21:00:15+00:00Added an answer on June 12, 2026 at 9:00 pm

    You can do the order in three places.

    1. In the initial query,
    2. In the foreach, or
    3. In the return

    Option 1:

    var rvInvoices =
        (from i in db.QB_INVOICES_HEADER
        where i.ClientID == cId
        select i).OrderByDescending(i => i.InvoiceNumber).ToList();
    

    Option 2:

    foreach (var itm in rvInvoices.OrderByDescending(i => i.InvoiceNumber))

    Option 3:

    return listInvoices.OrderByDescending(i => i.InvoiceNumber).ToList();

    I would suggest taking route 1 since it will run the order at the database level.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I want to say in advance that I truly appreciate anything
First of all, some background: I'm trying to get in a list of integers
First, I want to say that I'm out on deep water here, since I'm
First of all, I have only worked with scaffolding in rails. What I want
First of all I have seen that there are many questions about unrecognized selector
First I will show you example tables that my issue pertains to, then I
First of all, I'm uploading multiple images that goes through a for loop by
First of all, please correct me If I am wrong. I want to find
First of all, to get this out of the way, I've spent hours looking
First of all, this isn't for a keylogger, it's for an input in a

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.