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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:45:31+00:00 2026-05-21T07:45:31+00:00

Greetings I’m looking for creating a extension method including a linq query. What i’m

  • 0

Greetings

I’m looking for creating a extension method including a linq query.
What i’m looking for is either a method or extension method which can do something like this

var orderedList = OrderThisList<ModelName>(List<T> sourceList, //and something like m=>m.Username); 

Where ModelName is the entity and Username is the field of which I want to order.
The method would look something like

public List<T> OrderThisList<T>(//some linq property?)
{
    //What code goes here?
}
  • 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-21T07:45:32+00:00Added an answer on May 21, 2026 at 7:45 am

    EDIT: It’s still extremely unclear what this question is all about, but it sounds like we’re dealing with in-memory collections rather than LINQ to SQL etc.

    If the problem with using OrderBy is that it doesn’t sort the list in-place, you should be using List<T>.Sort(), possibly passing in a custom comparator.

    My MiscUtil project has a few helper types which may help you. For example:

    var comparison = ProjectionComparer<ModelType>.Create(m => m.SomeProperty)
                                                  .ThenBy(m => m.SomeOtherProperty);
    list.Sort(comparison);
    

    If you’re using LINQ to SQL and you’ve got a data context, you could use:

    public List<TSource, TKey> OrderThisList<TSource, TKey>(
        Expression<Func<TSource, TKey>> ordering)
    {
        return dataContext.GetTable<TSource>()
                          .OrderBy(ordering)
                          .ToList();
    }
    

    Now obviously that requires two type arguments, and you only want to specify one. There are various ways round this – basically you’d want to end up with a generic type and a method with one type argument (TKey) which can be inferred. For example:

    var list = Orderer<ModelType>.Create(dataContext)
                                 .OrderThisList(m => m.SomeProperty);
    

    It’s somewhat round-the-houses though considering that OrderBy is already available… could you explain why you want this, and also what LINQ provider is involved?

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

Sidebar

Related Questions

Greetings, I have a particular object which can be constructed from a file, as
Greetings, I have three TS variables resembling something like the following: data <- read.csv(...)
Greetings. I'm looking for a way to parse a number of XML files in
Greetings! I'm working on wrapping my head around LINQ. If I had some XML
Greetings, I'm trying to find either a free .NET library or a command-line executable
Greetings, I need a way (either via C# or in a .bat file) to
Greetings, I have a complicated scenario to handle. I have a wsdl file which
Greetings, creating my first MVVM based WPF app and trying to figure out why
Greetings, I am changing the width of an element which serves as a bar
Greetings, this is my very first question and I just do programming as 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.