I have three tables "Applications", "UserPermissions" and "ADPermissions".
Applications table contains list of applications. UserPermissions table defines which user is allowed to manage a particular application. Similarly "ADPermissions" table defines which AD Group has permissions to manage the application.
When a user login to an Administration Application (a web site), I have to display all the applications that he has access to based on his alias and all the AD groups that he belongs to. I am trying to write a Linq query like below but this gives me duplicate results. Also I have few other questions.
//List of groups from AD
var groups = (from g in UserPrincipal.Current.GetGroups()
select g.Name).ToArray<String>();
IdentityContext context = new IdentityContext();
var apps =
(from a in context.Applications
join up in context.UserPermissions on a.Id equals up.ClientId into appUsers
from up in appUsers.DefaultIfEmpty()
join gp in context.ADPermissions on a.Id equals gp.ClientId into appGroups
from gp in appGroups.DefaultIfEmpty()
select new
{
Id = a.Id,
ClientId = a.ClientId,
DisplayName = a.ClientName,
Enabled = a.Enabled,
ClientUri = a.ClientUri,
UserPermissions = a.UserPermissions,
GroupPermissions = a.ADPermissions
}).ToList().Distinct();
- How can I get unique results for this scenario?
- How can I apply filter to the above group based on the AD group names that I have instead of filtering the data after retrieving form SQL server?
- Is this a right approach?
Please help.