Skip to main content

GetWebRoleByName

/// <summary>
/// Retrieves a web role entity by its name from the adx_webrole entity.
/// </summary>
public Entity GetWebRoleByName(IOrganizationService service, string webRoleName)
{
QueryExpression webRoleQuery = new QueryExpression("adx_webrole")
{
ColumnSet = new ColumnSet("adx_name"),
Criteria = new FilterExpression
{
Conditions = { new ConditionExpression("adx_name", ConditionOperator.Equal, webRoleName) }
}
};

EntityCollection results = service.RetrieveMultiple(webRoleQuery);
return results.Entities.FirstOrDefault(); // Return the first match or null
}