2

My ApplicationUser class has a property called CompanyID.

All users are tied to a specific company. Now I'd like to list user accounts by CompanyID but can't figure out how to do it, UserManager.findxxx seem to be limited to whats built in and I can't seem to query it about custom properties.

Yurii
  • 4,811
  • 7
  • 32
  • 41
user81993
  • 6,167
  • 6
  • 32
  • 64
  • What is the name of your DbContext ? see: http://stackoverflow.com/questions/18773838/how-to-obtain-a-list-of-users-from-asp-net-identity – Ofiris Oct 01 '14 at 18:08

2 Answers2

3

Incase you extended the User model class with the CompanyId field:

var context = new ApplicationDbContext();

var usersByCompanyId = context.Users.Where(user => user.CompanyID == 1234).ToList();
Ofiris
  • 6,047
  • 6
  • 35
  • 58
0

use bottom code for get custom ApplicationUser in identity with custom property

var context=new AuthContext();
var result=context.Users.OfType<ApplicationUser>.SingleOrDefault(item => item.NationalCode == "");
pejman
  • 740
  • 7
  • 13