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

  • Home
  • SEARCH
  • 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 3281288
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:47:57+00:00 2026-05-17T19:47:57+00:00

Lets say I have a table called Projects in my SQL server. My dbml

  • 0

Lets say I have a table called Projects in my SQL server.
My dbml file has the Project object, and I use a list of Projects in multiple views of my MVC application.

The thing is: Ordering.

By default then you use linq the Projects are ordered by ID.

lets say I want them ordered by Name and then by Code.

_db.Projects.Ordery(q=>q.Name).ThenBy(q=>q.Code)

easy.

Now, I use this list of projects in several views, with different statements in the Where clause.

everywhere i need to add the same .Ordery(q=>q.Name).ThenBy(q=>q.Code)

this is not DRY.

If I were to change the order to make it first by code then by name i need to change that in several places.

What is my question: How do I DRY up the ordering. How would I have 1 place, where I define how the ordering of a list of Projects should be done.

surely I cant be the first with this kind of question. Tips will be very welcome.

  • 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-05-17T19:47:57+00:00Added an answer on May 17, 2026 at 7:47 pm

    You could easily write your own extension method (or even normal method) to do this:

    public static IQueryable<Project> InStandardOrder
        (this IQueryable<Project> source)
    {
        return source.OrderBy(q => q.Name).ThenBy(q => q.Code);
    }
    

    then just use:

    _db.Projects.InStandardOrder()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a table in a sql server 2000 database called TransactionType:
Lets say I have one table called REVIEWS This table has Reviews that customers
Lets say I have a table in MySQL called articles, that has a column
Lets say I have a table called Employees , and each employee has a
so lets say i have a table called data data id | date |
Lets say I have the following table called assets with the following fields: id
Let's say I have a table called Event which has a to-many relationship with
In MS Transact SQL, let's say I have a table (Orders) like this: Order
Hoping someone can help me out with this. Lets say I have a table
Let's say I have a table called 'species' with 3 columns: 'Id', 'ancestorId' and

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.