Solved

How can I use DISTINCT in LINQ?

Posted on 2009-07-02
2
240 Views
Last Modified: 2013-11-11
I have written the attached linq query but I only want to return data where the "ApplicantName" and  "vdv.Title" are DISTINCT.....possible?

Thanks.
var query = from ada in db.ApplicantDetails
                    join vdv in db.VacancyDetails on ada.VacancyID equals vdv.VacancyID
                    join adag in db.AgencyDetails on ada.AgencyID equals adag.AgencyID
                    join aaa in db.AgencyAgents on adag.AgencyID equals aaa.AgencyID
                    join rlv in db.ResultLookups on ada.ResultCode equals rlv.ResultCode
                    join aia in db.ApplicantInterviews on ada.ApplicantID equals aia.ApplicantID into appinterviews
                    from aia in appinterviews.DefaultIfEmpty()
                    orderby ada.LastName
                    select new { ada.ApplicantID, ada.VacancyID, ada.AgencyID, ada.ResultCode, ApplicantName = ada.Salutation + ' ' + ada.FirstName + ',' + ' ' + ada.LastName, ada.Address, ada.Phone, ada.Email, ada.CVFilePath, vdv.Title, ClosingDate = vdv.ClosingDate.ToShortDateString(), adag.Company, rlv.ResultDescription, aaa.ContactFirstName, aaa.ContactLastName, aaa.AgentPhone, Successful = (aia.Successful == null) ? false : (aia.Successful) };
 
        e.Result = query;

Open in new window

0
Comment
Question by:Shepwedd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 500 total points
ID: 24761794

IEnumerable<Search> myDistinctSearches = var mySearches = context.Searches
   .Where(s => s.resultCount > 0)
   .OrderByDescending(s => s.dateCreated)
   .Distinct(new MyComparer())
   .Take(5);
 
public class MyComparer : IEqualityComparer<Search>
{
   public bool Equals(Search x, Search y) {
      return x.searchPhrase == y.searchPhrase;
   }
 
   public int GetHashCode(Search obj) {
      return obj.searchPhrase.GetHashCode();
   }
}
 
 
IEnumerable<Search> myDistinctSearches = var mySearches = context.Searches
   .Where(s => s.resultCount > 0)
   .OrderByDescending(s => s.dateCreated)
   .ToList()
 
   .Distinct(new MyComparer())

Open in new window

0
 

Author Comment

by:Shepwedd
ID: 24761810
wow! but how would i impliment the distinct through your suggestion?

thanks.
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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