简体   繁体   English

ASP.NET 标识关系

[英]ASP.NET Identity relationship

I have a question.我有个问题。 I'm using ASP.NET CORE Identity(Individual User Accounts).我正在使用 ASP.NET CORE 身份(个人用户帐户)。 It's already creating a separate database independent of my project.它已经创建了一个独立于我的项目的单独数据库。 In my project, there are things I need to list that belong to the user.在我的项目中,我需要列出属于用户的内容。 How can I do this ?我怎样才能做到这一点 ?

Database1-> ASP.NET CORE Identity Database (this database was created automatically)

Database2-> My App database

In Database2 Example Code;在 Database2 示例代码中;

public class Report:BaseModel
{
    public string Title { get; set; }
    public string Description { get; set; }
    public DateTime DateTime { get; set; }
    public int UserId { get; set; } //(IT MUST BE ASP.NET USER TABLE)
    public User User { get; set; }  //(IT MUST BE ASP.NET USER TABLE)
}

First make sure that you have OnModelCreating on your DbContext class with base call首先确保你的 DbContext 类上有 OnModelCreating 和基本调用

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
}

then add your class然后添加你的班级

public class Report : BaseModel
{
    public string Title { get; set; }
    public string Description { get; set; }
    public DateTime DateTime { get; set; }
    public ApplicationUser User { get; set; }
}

then call migrations add-migration Report and Update-Database然后调用迁移add-migration ReportUpdate-Database

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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