public static void RoleSearch(string term, Action<EntityCollection> callback,string typeName)
{
string recordTypeFilter = string.Empty;
if (typeName != null)
{
// find the entity type code from the type name
int? etc = GetEntityTypeCodeFromName(typeName);
// Filter by the currently select role
recordTypeFilter = String.Format(@"
<filter type='or'>
<condition attribute='associatedobjecttypecode' operator='eq' value='{0}' />
<condition attribute='associatedobjecttypecode' operator='eq' value='0' />
</filter>", etc);
}
string fetchXml = @"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true' >
<entity name='connectionrole' >
<attribute name='category' />
<attribute name='name' />
<attribute name='connectionroleid' />
<attribute name='statecode' />
<order attribute='name' descending='false' />
<link-entity name='connectionroleobjecttypecode' from='connectionroleid' to='connectionroleid' >
{1}
</link-entity>
<filter type='and'>
<condition attribute='name' operator='like' value='%{0}%' />
</filter>
</entity>
</fetch>";
fetchXml = string.Format(fetchXml, XmlHelper.Encode(term), recordTypeFilter);
OrganizationServiceProxy.BeginRetrieveMultiple(fetchXml, delegate(object result)
{
EntityCollection fetchResult = OrganizationServiceProxy.EndRetrieveMultiple(result, typeof(Entity));
callback(fetchResult);
});
}