title: How can I get all users with ASP.NET Identity based on a property?
body: <p>I trying something quite simple but for whatever reason it does not work, and for that reason I here to see if something gives me any light, and I could not find examples or solutions somewhere else (Bing/google)</p>
  
  <p>The problem is quite simple I am using a slightly modified ApplicationUser class:</p>
  
  <pre><code> public class ApplicationUser : IdentityUser
  {
      public virtual Guid BusinessId { get; set; }
  }
  </code></pre>
  
  <p>With the following helper (Extension method):</p>
  
  <pre><code>public static Guid GetBusinessId(this IIdentity user)
      {
           var manager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(new ApplicationDbContext()));
           var currentUser = manager.FindById(user.GetUserId());
  
          return currentUser.BusinessId;
      }
  </code></pre>
  
  <p>Then finally the method that is "causing" the issue:</p>
  
  <pre><code>public IQueryable&lt;ApplicationUser&gt; Get()
      {
          var userManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(new ApplicationDbContext()));
  
          Guid businessId = this.User.Identity.GetBusinessId();
          var users = userManager.Users.Where(u =&gt; u.BusinessId == businessId);
  
          return users;
      }
  </code></pre>
  
  <p>What happens here is that when I query Users, I get nothing but it should at least get the current logged in User, since he has the proper businessId.</p>
  
  <p>If I put a break point on the users query and try anything like "ToList()" or "ToList()[0]" on the immediate window I get the following:</p>
  
  <pre><code>?users.ToList()
  Count = 1
  [0]: Could not evaluate expression
  ?users.ToList()[0]
  An internal error has occurred while evaluating method System.Collections.Generic.List`1[T].get_Item().
  </code></pre>
  
  <p>Any ideas why, or is there a "right" way of doing this?</p>
  
  <p>Thanks</p>