Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Source code:

public IEnumerable<Customer> GetAllCustomers()
        {
            IEnumerable<Customer> tempCustomer;

            try
            {
                tempCustomer = (from p in DatabaseConnection.Customers select p);
                return tempCustomer;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }



Can I use Order By function to get the list sorted before returning? And can any1 give an example? Or are there any other solution to do it sorted?
Posted
Updated 15-Jan-10 3:56am
v2

Why not use the orderby LINQ clause in your LINQ query. Assuming a Customer is an object with a property Name:

tempCustomer = (from p in DatabaseConnection.Customers orderby p.Name select p);


Slightly off topic, but I also suggest you replace IEnumerable with an appropriate IEnumerable<T> if possible.
 
Share this answer
 
orderby was excatly what I needed, just missed where in the syntax to add it. Worked great...

The IEnum is already type casted in the original code, so the ot was relevant tho it was ot. Thnx for your assistance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900