C# 实体框架联合和不同类型的Except查询
我想使用站点角色的操作的用户实体,但点是外部操作实体,操作数据将由外部操作实体过滤 在外部实体中: 如果Type property==1,则这将是动作实体的联合C# 实体框架联合和不同类型的Except查询,c#,.net,linq,entity-framework,entity-framework-4,C#,.net,Linq,Entity Framework,Entity Framework 4,我想使用站点角色的操作的用户实体,但点是外部操作实体,操作数据将由外部操作实体过滤 在外部实体中: 如果Type property==1,则这将是动作实体的联合 如果Type property==0,则此操作实体除外 public class User { public int Id { get; set; } public string Email { get; set; } public string UserName { get;
如果Type property==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; }
}
公共类用户
{
公共int Id{get;set;}
公共字符串电子邮件{get;set;}
公共字符串用户名{get;set;}
公共字符串密码{get;set;}
公共ICollection站点角色{get;set;}
公共ICollection外部操作{get;set;}
}
公共类站点角色
{
公共int Id{get;set;}
公共字符串说明{get;set;}
公共虚拟ICollection操作{get;set;}
公共虚拟ICollection用户{get;set;}
}
公共集体诉讼
{
公共int Id{get;set;}
public int UserId{get;set;}
public int ActionId{get;set;}
公共字节类型{get;set;}
公共虚拟操作操作{get;set;}
公共虚拟用户用户{get;set;}
}
公共集体诉讼
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串ActionName{get;set;}
公共字符串控制器名称{get;set;}
公共ICollection站点角色{get;set;}
公共虚拟ICollection外部操作{get;set;}
}
最后,我的解决方案如下
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();
我不明白你想说什么?你能澄清你的实际问题是什么吗?展示你的linq声明应该能澄清很多。我做了,但很难解释。很抱歉。