如何在 ASP.NET IDENTITY 中添加自定义 table?

How to add custom table in ASP.NET IDENTITY?

我在我的 Web 表单应用程序中使用 ASP.NET Identity。 下面是我现在的身份 tables:

当前身份tables

 - Role
 - User
 - UserClaim
 - UserLogin
 - UserRole

我需要添加一个新的 table 来存储额外的信息。

新 Table:用户日志

里面的字段新 table:

如何添加此自定义 table?我知道如何在现有 table 中添加自定义字段,但我不知道如何实现。

感谢您为解决我的问题所做的努力。

首先,我建议您稍微了解一下 Code-First Entity Framework,因为关于用户的 table 就是这样当您第一次创建 New MVC5 Application.

时创建

Here 如果您想使用通过 EntityFramework.

创建的代码优先数据库,您可以找到它是如何实现的

了解一些核心内容后,您可以转到 Models 文件夹中的项目,直接转到> AccountModel.cs

那里有一个扩展 DbContext 的 Class,它内部包含构造函数,该构造函数可以访问即将使用数据库的连接字符串。

如果你太懒惰先阅读代码,那么重要的东西很重要:

DbSet表示dbset里面的model,即将被创建成table。 class 中的变量是即将创建的列。但是如果你想要外键之类的东西,你肯定必须先阅读代码。

祝你好运!

public class ApplicationUser : IdentityUser
{

    public virtual ICollection<UserLog> UserLogs { get; set; }

}

public class UserLog
{
    [Key]
    public Guid UserLogID { get; set; }

    public string IPAD { get; set; }
    public DateTime LoginDate { get; set; }
    public string UserId { get; set; }

    [ForeignKey("UserId")]
    public virtual ApplicationUser User { get; set; }
}

public System.Data.Entity.DbSet<UserLog> UserLog { get; set; }