Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I use DISTINCT in LINQ?

Posted on 2009-07-02
2
Medium Priority
?
242 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 1000 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

704 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