Retrieve records from an intersect table via LINQ

Retrieve records from an intersect table via LINQ

#region Retrieve records from an intersect table via LINQ

// Obtain the Organization Context.
OrganizationServiceContext context = new OrganizationServiceContext(_serviceProxy);

// Create Linq Query.
var roles = (from r in context.CreateQuery<Role>()
join s in context.CreateQuery<SystemUserRoles>() on r.RoleId equals s.RoleId
where s.SystemUserId == _userId
orderby r.RoleId
select r.Name);

// Display results.
foreach (var role in roles)
{
  Write Logic for desired fields
}

#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