C# 与ApplicationUser类的一对多关系
我有一个C# 与ApplicationUser类的一对多关系,c#,asp.net-mvc,entity-framework,asp.net-identity-2,C#,Asp.net Mvc,Entity Framework,Asp.net Identity 2,我有一个用户类: public class User { public int UserID { get; set; } public string UserName { get; set; } public string Email { get; set; } public virtual ICollection<Project> Projects { get; set; } } 如您所见,用户
用户
类:
public class User
{
public int UserID { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public virtual ICollection<Project> Projects { get; set; }
}
如您所见,用户
和项目
之间存在一对多关系。
我想使用Identity
的ApplicationUser
类,而不是我的User
类。因此,如果我将IdentityModels.cs
更改为以下内容是否可以:
public class ApplicationUser : IdentityUser
{
public int UserID { get; set; }
public string ProjectTitle { get; set; }
public virtual User User { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
到该文件中的每个ViewModel
最后,我应该如何更改项目
类?我应该这样做:
public class Project
{
public int ProjectID { get; set; }
public int UserID { get; set; }
public string ProjectTitle { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}
如果你能回答我这个长问题,我将非常高兴。谢谢。为什么要在
IdentityModels.cs
中使用公共字符串项目标题{get;set;}
?这不应该与Project.cs有关吗
我错误地将它们粘贴到了问题上。我编辑了这个问题。谢谢
public string Email { get; set; }
public int UserID { get; set; }
public class Project
{
public int ProjectID { get; set; }
public int UserID { get; set; }
public string ProjectTitle { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
}