I'm a bit new to Linq and hoping someone could help me on something I'm currently strugling.
I currently have 2 list
public IQueryable<TRole> Roles
{
get
{
var roles = new List<TRole>();
roles.Add(CreateIdentityRole("Chairman", "Voorzitter"));
roles.Add(CreateIdentityRole("Treasurer", "Penningmeester"));
roles.Add(CreateIdentityRole("Ranking Responsible", "Rankingverantwoordelijke"));
roles.Add(CreateIdentityRole("Competition Responsible", "Competitieverantwoordelijke"));
roles.Add(CreateIdentityRole("Webmaster", "Webbeheerder"));
roles.Add(CreateIdentityRole("Secretary", "Secretaris"));
foreach(TRole role in roles)
{
if (!_roles.Contains(role))
_roles.Add(role);
}
return _roles.AsQueryable<TRole>();
}
}
private TRole CreateIdentityRole(string id, string name)
{
TRole role = (TRole)Activator.CreateInstance(typeof(TRole));
role.Id = id;
role.Name = name;
return role;
}
public void InitializePrivacy(IdentityUser user)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var roleManager = new RoleStore<IdentityRole>();
var roles = roleManager.Roles;
List<string> userRoles = manager.GetRoles(user.Id);
}
right now I want to use Linq to get all roles which are not found in userRoles. Because the roles is a Queryable I do not really now how to achieve such result.
Queryableis a static class which provides methods forIQueryableimplementations. You can't create an instance of it.