如何分隔个人资料信息

时间:2015-01-08 18:16:31

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

我正在使用带有EF6的asp.net mvc5构建一个应用程序。我能够进行身份验证部分,甚至可以在我们选择个人用户帐户选项时将信息添加到表mvc5自动生成的表中。我现在想做的是创建一个用户配置文件。我知道我可以使用相同的表,但我想创建另一个,所以我可以将身份验证信息与个人资料信息分开。这是我到目前为止所尝试的:

public class UserProfile : IdentityUser
{
    public virtual ProfileInfo Profile { get; set; }
}

public class ProfileInfo  : IdentityUser
{
    public int Id { get; set; }
    public string nome { get; set; }
    public string apelido { get; set; }
    public string idade { get; set; }
    public string sexo { get; set; }
    public string profissao { get; set; }
    public string nacionalidade { get; set; }
}

public class ProfileDbContext : IdentityDbContext<ProfileInfo>
{
    public ProfileDbContext()
        :base ("DefaultConnection" , throwIfV1Schema: false)
    {
    }
    public DbSet<ProfileInfo> Perfil { get; set; }
    public System.Data.Entity.DbSet<ProfileInfo> ProfileInfo { get; set; }
}

我无法在其他任何地方找到相关信息。我看到的所有教程都使用AspnetUser表存储配置文件信息。

编辑: 好的,所以现在我发现我需要的只是对表Asp.netUsers的foreignKey。问题是,该表的主键是varChar ...而不是int。该死的微软......

1 个答案:

答案 0 :(得分:1)

如评论中所述,定义了从UserProfileProfileInfo的关系。

public class UserProfile : IdentityUser
{
    [ForeignKey("ProfileInfo")]
    public int ProfileInfoId Profile { get; set; }
    public ProfileInfo ProfileInfo { get;set; }
}