[Solved] How to convert for each loop over objects list property into linq statement


Try something like this:

List<User> users  = db.Users.Where(user => user.Roles.Any(r => r.Name == role)).ToList();

This is the case if you want to compare role names otherwise implement your Equal method

2

solved How to convert for each loop over objects list property into linq statement