[size=12px]使用identity 系统会默认生成 User、Role 和UserRole三张表,但是我在User表中加了CompanyId字段。我想查询当前 CompanyId是001的Role 是 01(admin)的所有用户。
如果是Sql直接就:select * from user,userrole where user.userid=userrole.userid and user.companyid="001" and userrole.roleid="01" 就好了。但是由于小弟刚刚接触MVC比较愚钝,用linq不管怎么试都不行。我把我试的代码贴在下面:尝试一:
AppRole role = RoleManager.FindById("R02");
var users = UserManager.Users.Where(u => u.Roles= role && u.Company="001" );尝试二:
var users= UserManager.Users.Where(u => u.Roles.SingleOrDefault().RoleId = "01" && u.Company="001" )
[/size]AppRole 类:
public class AppRole : IdentityRole
{ public AppRole() : base() { } public AppRole(string name) : base(name) { }
}
AppUser 类:
public class AppUser : IdentityUser
{
// 这里将放置附加属性
public AppUser() : base() { }
[Required]
public int CompanyId { get; set; }
public virtual Company Company { get; set; }
}
AppUserRole类 :
public class AppUserRole:IdentityUserRole
{
public AppUserRole() : base() { }
}
如果是Sql直接就:select * from user,userrole where user.userid=userrole.userid and user.companyid="001" and userrole.roleid="01" 就好了。但是由于小弟刚刚接触MVC比较愚钝,用linq不管怎么试都不行。我把我试的代码贴在下面:尝试一:
AppRole role = RoleManager.FindById("R02");
var users = UserManager.Users.Where(u => u.Roles= role && u.Company="001" );尝试二:
var users= UserManager.Users.Where(u => u.Roles.SingleOrDefault().RoleId = "01" && u.Company="001" )
[/size]AppRole 类:
public class AppRole : IdentityRole
{ public AppRole() : base() { } public AppRole(string name) : base(name) { }
}
AppUser 类:
public class AppUser : IdentityUser
{
// 这里将放置附加属性
public AppUser() : base() { }
[Required]
public int CompanyId { get; set; }
public virtual Company Company { get; set; }
}
AppUserRole类 :
public class AppUserRole:IdentityUserRole
{
public AppUserRole() : base() { }
}
解决方案 »
- 请教关于arcgis图层join的问题
- A标签绑javascript:showPopWin的问题
- 起止时间选择的问题,不知道为什么。。。。。。~~~~(>_<)~~~~
- 问题又来了?
- 能不能指定DataList不显示指定的数据项?
- 有没有好的测试asp.net占用系统资源,或者模拟客户访问速度,还有一切能够测试.net性能所有方法,顶者有分,谢谢!
- 在web的DataGrid中怎么让第一列显示行号?
- binddata()的使用
- 水晶报表画表格问题:如何使竖线和横线正好相交,不出头,不漏空?
- 求js计算后的值怎么设置到网页上
- 排队叫号网站,程序大概思路怎么样,一点头绪也没有
- 最近刚学习.net+mysql+ef6生成实体是出错,有大神帮忙看一下
from u in user
join p in userrole on u.userid e equals p.userid into g
where u.companyid="001" && p.roleid="01"
select new{};
lambda:
var sg = Users.Join(userrole, u => u.userid, d => d.userid, (u,d) => new { u, d }).where(o=>o.u.companyid="001" && o.d.roleid="01");