I want to retrieve data from the Identity-table dbo.AspNetUsers, but I haven't figured out how to query it.
This is my db-context:
public class ProjectsDbContext : IdentityDbContext<IdentityUser>
{
public ProjectsDbContext(DbContextOptions<ProjectsDbContext> options) : base(options) { }
public DbSet<Project> Projects { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
if (modelBuilder == null)
{
throw new NullReferenceException();
}
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Project>()
.HasMany(c => c.ChildProjects)
.WithOne(p => p.ParentProject)
.HasForeignKey(p => p.ParentProjectId);
}
}
This is my User-class:
public class User : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
This is the query I have, which doesn't work:
List<User> projectOwners = await db.Users.ToListAsync();
The error message I get is:
Cannot implicitly convert type 'System.Collections.Generic.List<Microsoft.AspNetCore.Identity.IdentityUser>' to 'System.Collections.Generic.List<Projects.Models.User>'
If I replace List<User> with var in the query, the error goes away, but the collection I get does not contain any of the properties from my own User-class.
How do I access the AspNetUsers, including my own extra properties defined in User?