Reputation: 437
I'm building an application using asp.net mvc5 with EF6. I was able to do the authentication part and even add information to the tables witch mvc5 auto-generates when we choose the Individual user accounts option. What i wanted to do now is to create a user profile. I know i can use the same table but i wanted to create another one so i can separate Authentication info from profile info. This is what i tried so far:
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; }
}
i couldn't find information about this anywhere else. All the tutorials i see use the AspnetUser table to store profile information.
EDIT: OK, so now i have found that what i need is just a foreignKey to the table Asp.netUsers. Problem is, the primary key from that table is a varChar... not an int. Damn Microsoft...
Upvotes: 0
Views: 171
Reputation: 11914
As mentioned in the comments, defined a relationship from UserProfile
to ProfileInfo
.
public class UserProfile : IdentityUser
{
[ForeignKey("ProfileInfo")]
public int ProfileInfoId Profile { get; set; }
public ProfileInfo ProfileInfo { get;set; }
}
Upvotes: 1