I am using the LINQ to CRM provider.
I am querying the information then I am using LINQ to query the LINQ to CRM query so I can use GroupBy, since the LINQ to CRM provider does not support it. This is what I have so far.
var linqQuery = (from r in orgServiceContext.CreateQuery("opportunity")
join c in orgServiceContext.CreateQuery("contact") on
((EntityReference)r["new_contact"]).Id equals c["contactid"] into opp
from o in opp.DefaultIfEmpty()
select new
{
OpportunityId = !r.Contains("opportunityid")
? string.Empty : r["opportunityid"],
CustomerId = !r.Contains("customerid")
? string.Empty : ((EntityReference)r["customerid"]).Name,
OwnerId = !r.Contains("ownerid")
? string.Empty : ((EntityReference)r["ownerid"]).Id.ToString(),
OwnerName = !r.Contains("ownerid")
? string.Empty : ((EntityReference)r["ownerid"]).Name.ToString(),
Priority = !r.Contains("opportunityratingcode")
? string.Empty : r.FormattedValues["opportunityratingcode"],
ContactName = !r.Contains("new_contact")
? string.Empty : ((EntityReference)r["new_contact"]).Name,
// ...
// other properties
});
var linqQuery2 = (from f in linqQuery.ToList()
group f by f.OwnerId into myGroup
select new
{
OrderCount = myGroup.Count()
});
But I also want to be able to query the other variables that are in linqQuery
from linqQuery2
.
So I would want something like:
var linqQuery2 = (from f in linqQuery.ToList()
group f by f.OwnerId into myGroup
select new
{
OwnerName = myGroup.OwnerName,
OrderCount = myGroup.Count()
});
Is this possible to do?