2012-03-24 73 views
0

我想用戶實體操作的的站點角色的,但關鍵是ExtraAction實體,行動數據將是ExtraAction實體過濾器,實體框架聯盟和除查詢不同類型

在ExtraAction實體

如果Type屬性== 1這是聯盟行動實體
如果Type屬性== 0這是除了行動實體

public class User 
    { 
     public int Id { get; set; } 
     public string Email { get; set; } 
     public string UserName { get; set; } 
     public string Password { get; set; } 

     public ICollection<SiteRole> SiteRoles { get; set; } 
     public ICollection<ExtraAction> ExtraActions { get; set; } 
    } 

    public class SiteRole 
    { 
     public int Id { get; set; } 
     public string Description { get; set; } 
     public virtual ICollection<Action> Actions { get; set; } 
     public virtual ICollection<User> User { get; set; } 
    } 

    public class ExtraAction 
    { 
     public int Id { get; set; } 
     public int UserId { get; set; } 
     public int ActionId { get; set; } 
     public byte Type { get; set; } 

     public virtual Action Action { get; set; } 
     public virtual User User { get; set; } 
    } 

    public class Action 
    { 
     public int Id { get; set; } 
     public string Name { get; set; } 
     public string ActionName { get; set; } 
     public string ControllerName { get; set; } 
     public ICollection<SiteRole> SiteRoles { get; set; } 
     public virtual ICollection<ExtraAction> ExtraActions { get; set; } 

    } 
+1

我不理解你所想要知道的?你能澄清你的實際問題是什麼嗎? – 2012-03-24 15:31:44

+0

顯示你的linq聲明應該澄清很多。 – 2012-03-24 19:05:16

+0

我做了,但很難解釋一點對不起。 – tobias 2012-03-24 19:26:31

回答

1

最後我的解決方案是低於

var list = dbContext.Actions.Where(u => 
       u.Roles.SelectMany(r => r.User).Any(su => su.Id == Id)).Select(row => new { Action = row }). 
       Union(dbContext.ExtraActions.Where(suea => suea.Type == 1 && suea.UserId == Id).Select(row => new { Action = row.Action })). 
       Except(dbContext.ExtraActions.Where(suea => suea.Type == 0 && suea.UserId == Id).Select(row => new { Action = row.Action })).ToList();