Ian Ian - 1 year ago 99
ASP.NET (C#) Question

How to get the Number of ApplicationUser in the AspNetUsers Table in ASP.Net MVC 5?

Is there any way to get the number of users in the

AspNetUsers
table which is automatically created by the
ASP.Net
MVC 5
?

In the
ApplicationDbContext
which is created automatically in the
IdentityModels.cs
file when you start a
ASP.Net MVC 5
project, I do not see something like:

public DbSet<ApplicationUser> ApplicationUsers { get; set; }


which is a typical way of representing and getting the entries in the database's table for a certain connection.

Answer Source

Your context is using Identity (probably v2) which means it inherits from IdentityDbContext, that is where you will see the users DbSet. So you should be able to write something like this:

var userCount = context.Users.Count();