title: Asp MVC Entity Framework Check if Permission Is In Role
body: <p>I have the following Model and I want a method to check if a permission is in a role. Currently I'm implementing this using the IsPermissionInRole method which does a for loop:</p>
  
  <pre><code>public class ApplicationRole : IdentityRole
  {
      public ApplicationRole() : base() { }
      public ApplicationRole(string name) : base(name) { }
  
      public virtual ICollection&lt;Permission&gt; Permissions { get; set; }
  
      public bool IsPermissionInRole(string _permission)
      {
          bool _retVal = false;
          try
          {
              foreach (Permission _perm in Permissions)
              {
                  if (_perm.Name == _permission)
                  {
                      _retVal = true;
                      break;
                  }
              }
          }
          catch (Exception)
          {
          }
          return _retVal;
      }
  
  }
  </code></pre>
  
  <p>Is there a more elegant way to do this perhaps using some linq query?</p>