2

I am trying to query data in CRM 2011 and I need to join an ActivityParty. I can't seem to find any good documentation on it. Has anyone done this before. This is my query so far:

var linqQuery = (from r in gServiceContext.CreateQuery("campaignresponse")
                 join c in gServiceContext.CreateQuery("contact") on ((EntityReference)r["customer"]).Id equals c["contactid"] into opp
                 join a in gServiceContext,CreateQuery("lead") on ((EntityReference)r["customer"]).Id equals c["leadid"] into opp
                 from o in opp.DefaultIfEmpty()
                 where  ((EntityReference)r["new_distributorid"]).Id.Equals(lProfileProperty.PropertyValue) && ((OptionSetValue)r["new_distributorstatus"]).Equals("100000002")
                 select new
                  { }

So if you look at the query what I am trying to do is join the contact Entity and the lead Entity to CamapaignResponse via the customer field and the customer field is an ActivityParty field. Any ideas on how to do this? Thanks!

1 Answers1

1

I'm having a hard time figuring out how your query is supposed to work, but I can tell you that you'll have an easier time if you generate Linq entities using the SDK. Then, instead of

from r in gServiceContext.CreateQuery("campaignresponse") where ...

you can just write

gServiceContext.CampaignResponseSet
 .Where(cr => cr.property == value)
 .Select(cr => new {cr, cr.childObject});

and so forth. You'll get strong typing and IntelliSense, too.

Jack
  • 10,943
  • 13
  • 50
  • 65