LINQ to Entities无法识别方法'System.String ToString()'方法++++++

时间:2019-05-16 08:08:02

标签: c# entity-framework

LINQ to Entities无法识别方法'System.String ToString()'方法。

List <MenuModels> _menus = 
    _entity.SubMenus
        .Where(x => x.RoleId.Split(',').ToString()  == _loginCredentials.UserRoleId)
        .Select(x => new MenuModels
        {
            MainMenuId = x.MainMenu.Id,
            MainMenuName = x.MainMenu.MainMenu1,
            SubMenuId = x.Id,
            SubMenuName = x.SubMenu1,
            ControllerName = x.Controller,
            ActionName = x.Action,
            RoleId = x.RoleId,
            RoleName=x.Role.Roles
        }).ToList(); 

https://i.stack.imgur.com/4gt8n.png

1 个答案:

答案 0 :(得分:1)

也许您想获得RoleId包含UserRoleId的所有子菜单。在这种情况下,您必须使用:

List<MenuModels> _menus = _entity.SubMenus.Where(x => x.RoleId.Contains(_loginCredentials.UserRoleId)).Select ...