简体   繁体   中英

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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM