Solved

Need Order by in LINQ

Posted on 2014-03-10
3
298 Views
Last Modified: 2016-02-10
New to Linq.

I need to add an order by on the new  AppResourceDetails().Need to order by on arg.GroupDescription

appResourceDetails = context.AppResources                    
                        .Where(ar => ar.AppId == appId && ar.GroupId != UserDefinedReports)
                        .Join(context.AppResourceGroups, ar => new { ar.GroupId, ar.AppId }, arg => new { arg.GroupId, arg.AppId },
                        (ar, arg) => new AppResourceDetails()
                        {
                              ResourceId = ar.ResourceId,
                              ResourceTypeId = ar.ResourceTypeId,
                              ResourceDescription = ar.ResourceDescription,
                              ResourceComment = ar.ResourceComment,
                              CreateDate = ar.CreateDate,
                              ExpirationDate = ar.ExpirationDate,
                              GroupId = ar.GroupId,
                              GroupDescription = arg.GroupDescription
                        }).ToList();

Appreciated
thank you
0
Comment
Question by:charlesbaldo
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39917984
Try it like this:

appResourceDetails = context.AppResources                    
                        .Where(ar => ar.AppId == appId && ar.GroupId != UserDefinedReports)
                        .Join(context.AppResourceGroups, ar => new { ar.GroupId, ar.AppId }, arg => new { arg.GroupId, arg.AppId },
                        (ar, arg) => new AppResourceDetails()
                        {
                              ResourceId = ar.ResourceId,
                              ResourceTypeId = ar.ResourceTypeId,
                              ResourceDescription = ar.ResourceDescription,
                              ResourceComment = ar.ResourceComment,
                              CreateDate = ar.CreateDate,
                              ExpirationDate = ar.ExpirationDate,
                              GroupId = ar.GroupId,
                              GroupDescription = arg.GroupDescription
                        }).OrderBy(gd => gd.GroupDescription).ToList();

Open in new window

0
 

Author Closing Comment

by:charlesbaldo
ID: 39918208
Perfect,  Thank you kindly
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39918291
Not a problem, glad to help.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now