Linq on Extended Identiy2 AspUserRoles Table

本文关键字:AspUserRoles Table Identiy2 Extended on Linq | 更新日期: 2023-09-27 18:35:37

我扩展用户角色如下:

public class ApplicationUserRole : IdentityUserRole
{
    public ApplicationUserRole() : base() { }
    public int? ModelPk { get; set; }
    public MasterModelType MasterModelType { get; set; }
}

现在,我想检查用户是否在特定 ModelPk 上具有特定角色。即。检查用户 A 在项目43 上是否具有角色 B。

Linq on Extended Identiy2 AspUserRoles Table

不完全确定,但也许尝试使用 lambda? 也许是这样的:

    private void testMethod()
    {
        IdentityRole ident = new IdentityRole();
        var Role = ident.Users.FirstOrDefault(a => Convert.ToInt32(a.RoleId) == ModelPk);
    }

更多详细信息可能会有所帮助。