Retrieve records from an intersect table via Fetch

Retrieve records from an intersect table via Fetch

#region Retrieve records from an intersect table via Fetch

// Setup Fetch XML.
StringBuilder linkFetch = new StringBuilder();
linkFetch.Append(“<fetch version=\”1.0\” output-format=\”xml-platform\” mapping=\”logical\” distinct=\”true\”>”);
linkFetch.Append(“<entity name=\”role\”>”);
linkFetch.Append(“<attribute name=\”name\”/>”);
linkFetch.Append(“<link-entity name=\”systemuserroles\” from=\”roleid\” to=\”roleid\” visible=\”false\” intersect=\”true\”>”);
linkFetch.Append(“<filter type=\”and\”>”);
linkFetch.Append(“<condition attribute=\”systemuserid\” operator=\”eq\” value=\”” + _userId + “\”/>”);
linkFetch.Append(“</filter>”);
linkFetch.Append(“</link-entity>”);
linkFetch.Append(“</entity>”);
linkFetch.Append(“</fetch>”);

// Build fetch request and obtain results.
RetrieveMultipleRequest efr = new RetrieveMultipleRequest()
{
Query = new FetchExpression(linkFetch.ToString())
};
EntityCollection entityResults = ((RetrieveMultipleResponse)_serviceProxy.Execute(efr)).EntityCollection;

// Display results.
foreach (var e in entityResults.Entities)
{
  Place your Logic for desired fields to retrieve
}

#endregion

Cheers,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s