I have a query that I need to execute against CRM. It is the equivalent of the following in SQL:
SELECT A.*, B.* FROM Table1 A INNER JOIN Table2 B ON A.ID = B.ID
I created a query and added a linkentity as follows:
link.JoinOperator = JoinOperator.Inner; link.LinkFromEntityName = EntityName.new_Table1.ToString(); link.LinkFromAttributeName = 'new_Table1ID'; link.LinkToEntityName = EntityName.new_Table2.ToString(); link.LinkToAttributeName = 'new_Table2ID'; query.LinkEntities = new LinkEntity[] { link };
However, it only returns the columns from new_Table1.
Is there a way to link in this fashion and return the columnns from both entities without having to create two queries?
QueryExpression doesn’t support this. You’ll need to use Fetch XML.
From ‘Using FetchXML’ in the SDK – you’ll end up with something like this:
If you haven’t used FetchXML yet, I highly recommend http://www.stunnware.com/?area=products&group=swtools4 for building and testing FetchXML. That way you can get a preview of your Result XML.