我想从Identity表dbo.AspNetUsers
中检索数据,但我还没找到如何查询它的方法。
这是我的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);
}
}
这是我的User
类:
public class User : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
这是我的查询,但它不起作用:
List<User> projectOwners = await db.Users.ToListAsync();
我收到的错误信息是:
如果我在查询中使用无法隐式将类型 'System.Collections.Generic.List<Microsoft.AspNetCore.Identity.IdentityUser>' 转换为 'System.Collections.Generic.List<Projects.Models.User>'
var
替换 List<User>
,则错误消失了,但是我获得的集合不包含我自己定义在 User
类中的任何属性。如何访问
AspNetUsers
,包括我自己在 User
中定义的额外属性?