- I have a class called Query.
- And I have a class Called Permissions
- Query has a Collection of Permissions
- I need to query the Queries for which a user has a permission.
but I am not sure how to make the where clause.
public class Query
{
public int QueryId { get; set; }
public string QueryName { get; set; }
public string QuerySql { get; set; }
public string CreatedBy { get; set; }
public string QueryType { get; set; }
public string Column1 { get; set; }
public string Operator1 { get; set; }
public string Value1 { get; set; }
public string Connector2 { get; set; }
public string Column2 { get; set; }
public string Operator2 { get; set; }
public string Value2 { get; set; }
public string Connector3 { get; set; }
public string Column3 { get; set; }
public string Operator3 { get; set; }
public string Value3 { get; set; }
public virtual ICollection<Permission> Permissions { get; set; }
}
public class Permission
{
public int PermissionId { get; set; }
public string UserName { get; set; }
}
public IQueryable<Query> GetQueriesForUser(string userName)
{
_context.Queries.Where(m=>m.Permissions.Contains(???))
}
So you want all the queries
where there is a permission for that query
where the username of the permission is the username of the user
You could use something like: