从ASP.NET中的EF读取标识用户信息

时间:2017-08-28 13:24:25

标签: c# entity-framework asp.net-core

我已经扩展了默认的asp.net核心身份用户,如下所示:

public class ApplicationUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public MyObject SomeObject { get; set; }
    public List<Email> AssociatedEmails { get; set; }
}

似乎所有用户数据都存储在一个名为AspNetusers的表中,但在ApplicationDbContext中没有这个定义,因此我无法在我的代码中引用它。

我需要能够从Entity Framework读取各种用户详细信息,并将用户记录与各种其他实体相关联,因此我需要能够通过EF访问用户实体。

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

class B { public: B(bool isThat) { if (isThat) aWay = new AThatWay(); else aWay = new AThisWay(); } void bar() { aWay->method(); } private: AWay *aWay = nullptr; } ApplicationDbContext,您可以编写自己的IdentityDbContext

IdentityDbContext<ApplicationUser>

并在启动类中使用它

public class YourApplicationDbContext : IdentityDbContext<YourApplicationUser>
{
    public YourApplicationDbContext (DbContextOptions options) : base(options) { }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);
    }
}