Sample code to find all Security Roles for a Team:

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using Xrm;
private List<Role> GetAllSecurityRolesForTeam(Guid teamId)
{
    // Initiate CRM-connection
    var conn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CONN"].ConnectionString);
    var service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
    var context = new OrganizationServiceContext(service);

    var roles = (from tr in context.CreateQuery<TeamRoles>()
        join r in context.CreateQuery<Role>() on tr.RoleId equals r.RoleId
        where tr.TeamId == teamId
        select r).ToList();

    return roles;
}

Observe: The above code requires a generated XRM early bound entity file for the Role and TeamRoles entities.