Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>var linqQuery = from r in orgServiceContext.CreateQuery("opportunity") join c in orgServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals c["systemuserid"] group r by ((EntityReference)r["ownerid"]).Id into oop select new { Key = oop.Key, Count = oop.Count(), Opportunities = oop //contains the list of opportunities grouped by OwnerId }; </code></pre> <p><code>Opportunities</code> contains a collection of IGrouping You must iterate through the collection <code>IEnumerable&lt;Microsoft.Xrm.Sdk.Entity&gt;</code> to create the list of opportunities with the members you are interested. (the projection you made by using the new operator)</p> <pre><code>var outputOpportunities = new ArrayList(); foreach (IGrouping&lt;Guid, Microsoft.Xrm.Sdk.Entity&gt; group in linqQuery) { foreach (Microsoft.Xrm.Sdk.Entity opportunity in group) outputOpportunities.Add (new { OpportunityId = !opportunity.Contains("opportunityid") ? string.Empty : opportunity["opportunityid"], CustomerId = !opportunity.Contains("customerid") ? string.Empty : ((EntityReference)opportunity["customerid"]).Name, Priority = !opportunity.Contains("opportunityratingcode") ? string.Empty : opportunity.FormattedValues["opportunityratingcode"], ContactName = !opportunity.Contains("new_contact") ? string.Empty : ((EntityReference)opportunity["new_contact"]).Name, Source = !opportunity.Contains("new_source") ? string.Empty : ((String)opportunity["new_source"]), CreatedOn = !opportunity.Contains("createdon") ? string.Empty : ((DateTime)opportunity["createdon"]).ToShortDateString(), Eval = !opportunity.Contains("new_distributorevaluation") || ((OptionSetValue)opportunity["new_distributorevaluation"]).Value.ToString() == "100000000" ? "NA" : opportunity.FormattedValues["new_distributorevaluation"].Substring(0, 2), EvalVal = !opportunity.Contains("new_distributorevaluation") ? "100000000" : ((OptionSetValue)opportunity["new_distributorevaluation"]).Value.ToString(), DistributorName = !opportunity.Contains("new_channelpartner") ? string.Empty : ((EntityReference)opportunity["new_channelpartner"]).Name, Notes = !opportunity.Contains("new_distributornotes") ? string.Empty : opportunity["new_distributornotes"], EstimatedCloseDate = !opportunity.Contains("estimatedclosedate") ? string.Empty : opportunity["estimatedclosedate"], MaturityValue = !opportunity.Contains("estimatedvalue") ? string.Empty : ((Money)opportunity["estimatedvalue"]).Value.ToString(), SentToDistributorOn = !opportunity.Contains("new_senttodistributoron") ? DateTime.MinValue.ToShortDateString() : ((DateTime)opportunity["new_senttodistributoron"]).ToShortDateString(), LeadStatus = !opportunity.Contains("new_leadstatus") ? string.Empty : ((OptionSetValue)opportunity["new_leadstatus"]).Value.ToString(), EmailedToRSM = !opportunity.Contains("new_emailedtorsm") ? string.Empty : opportunity.FormattedValues["new_emailedtorsm"], EmailedToDistributor = !opportunity.Contains("new_emailedtodistributor") ? string.Empty : opportunity.FormattedValues["new_emailedtodistributor"], Owner = !opportunity.Contains("ownerid") ? string.Empty : ((EntityReference)opportunity["ownerid"]).Name, OwnerEmail = !opportunity.Contains("internalemailaddress") ? string.Empty : ((String)opportunity["internalemailaddress"]) } ); } </code></pre> <p>Basically i took your query and added the <code>group by</code> operator and in the projection statement i put the count by ownerid.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload