このコードには問題があります。intersect メソッドを実行すると、すべて正常に動作します。
foreach の前に交差点でカウントを行うと、1 になります。
foreach の後、foreach の後に再度カウントすると 0 になるのはなぜですか? 常に 1 である必要があります...
var matchedRoles = roles.Intersect(user.Roles);
int before = matchedRoles.Count();
foreach (var matchedRole in matchedRoles)
{
user.Roles.Remove(matchedRole);
}
int after = matchedRoles.Count();
if (matchedRoles.Any())
{
accountRepository.Update(user);
}