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)
The problem is quite simple I am using a slightly modified ApplicationUser class:
public class ApplicationUser : IdentityUser
{
public virtual Guid BusinessId { get; set; }
}
With the following helper (Extension method):
public static Guid GetBusinessId(this IIdentity user)
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(user.GetUserId());
return currentUser.BusinessId;
}
Then finally the method that is "causing" the issue:
public IQueryable<ApplicationUser> Get()
{
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
Guid businessId = this.User.Identity.GetBusinessId();
var users = userManager.Users.Where(u => u.BusinessId == businessId);
return users;
}
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.
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:
?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().
Any ideas why, or is there a "right" way of doing this?
Thanks