2012-05-31 39 views
0
  1. 我有一個名爲Query的類。
  2. 我呼喚權限
  3. 查詢一類具有權限
  4. 的收藏我需要查詢用戶具有權限的查詢。

但我不知道如何使where子句。複雜EF查詢返回基礎對象,但過濾子對象

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(???)) 
} 

回答

3

所以,你希望所有的查詢
那裏是該查詢
許可該權限的用戶名是用戶的用戶名

您可以使用類似:

_context.Queries.Where(q => q.Permissions.Any(p => p.UserName.Equals(userName)));