与ApplicationUser类

时间:2015-11-29 14:18:38

标签: c# asp.net-mvc entity-framework asp.net-identity-2

我有这个User课程:

 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; }

    }

这个Project班级:

  public class Project
    {
        public int ProjectID { get; set; }
        public int UserID { get; set; }
        public string ProjectTitle { get; set; }

        public virtual User User { get; set; }

    }

您可以看到UserProject之间存在一对多的关系。 我想使用User Identity课程,而不是我的ApplicationUser课程。如果我将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")
        {
        }
    }

我应该如何更改AccountViewModel.cs?我应该添加这些

    public string Email { get; set; }

    public int UserID { get; set; }

到该文件中的每个ViewModel?

最后我应该如何更改Project课程?我应该这样做:

 public class Project
    {
        public int ProjectID { get; set; }
        public int UserID { get; set; }
        public string ProjectTitle { get; set; }

        public virtual ApplicationUser ApplicationUser { get; set; }

    }

如果你能回答我这个长期的问题,我会很高兴的。感谢。

0 个答案:

没有答案