Asp.NET Identity Core IsInRole InvalidOperationException:Sequence包含多个元素

时间:2017-07-14 12:52:26

标签: c# asp.net entity-framework-6 asp.net-identity .net-4.5

我有这段代码:

...
var _context = new MyDbContext();     
var _userManager = new UserManager<User>(new UserStore<User>(_context));
...
public bool IsInRole(string userId, string roleName)
{
    return _userManager.IsInRole(userId, roleName); //InvalidOperationException
}

引发此异常:

  

类型&#39; System.InvalidOperationException&#39;的例外情况发生在mscorlib.dll中但未在用户代码中处理

     

附加信息:序列包含多个元素

Visual Studio 2015

.NET 4.5

Microsoft AspNet Identity Core 2.2.1

实体框架6

InvalidOperationException

1 个答案:

答案 0 :(得分:1)

IdentityRoles表中有重复的名称:

GROUP BY tbl_language_code LIMIT 1

enter image description here

删除不必要的行解决了问题。