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

  • SEARCH
  • Home
  • 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 8052703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:36:54+00:00 2026-06-05T07:36:54+00:00

I am trying to Select Distinct set using a LINQ to CRM query and

  • 0

I am trying to Select Distinct set using a LINQ to CRM query and it continues to return dupilicate records. The query I am using is:

  var linqQuery = (from r in gServiceContext.CreateQuery("opportunity")
                   join c in gServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals c["accountid"]
                   join u in gServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals u["systemuserid"]
                   where (r["statuscode"].Equals("100000004") || r["statuscode"].Equals("100000003")) && r["statecode"].Equals("Open")
                   where u["internalemailaddress"].Equals(_currentUser.Email)

                       select new
                           {
                                 AccountId = !c.Contains("accountid") ? string.Empty : c["accountid"],
                                 Account = !c.Contains("name") ? string.Empty : c["name"]
                             }).Distinct();

Am I missing something to make .Distinct() work? Or is there a better way to do it?

  • 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-06-05T07:36:55+00:00Added an answer on June 5, 2026 at 7:36 am

    The Distinct call without an explicit comparer simply uses the default equality comparer, which in the case of anonymous types boils down to Object.Equals. This is overridden in anonymous types to be equal if all properties of the type are equal. In this case it will check the AccountId and Account properties.

    I suspect this is working and that the values are different in terms of case (as strings compare case-sensitive by default) or they are in fact distinct and you just can’t see it.

    Luckily, it has nothing to do with the CRM-specific Linq provider.

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

Sidebar

Related Questions

I'm trying to return a set of distinct values from a DataTable using LINQ.
I'm trying ro execute this dql query SELECT DISTINCT a FROM Ipf\Model\Entity\Transaction t INNER
I'm trying to select DISTINCT rows from a view using ROW_NUMBER() OVER for paging.
I am trying to bring some data from Dynamics CRM 2011 using LINQ. The
I am trying to execute the following Query select distinct pincode as Pincode,CAST(Date_val as
I'm trying to perform a DISTINCT clause on a query like this SELECT DISTINCT
Im trying to replicate the following sql in Nhibernate ICriteria SELECT DISTINCT AP.ID FROM
I'm trying to SELECT, and get a unique result set, from a MySQL database,
I'm trying to select distinct substring values of a field and count the number
So I'm running MySQL version 5.1.4 and I'm trying to select distinct by 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.