this is my ApplicationUser class.I have added only one new property ----
public class ApplicationUser : IdentityUser
{
//public ApplicationUser()
//{
// UserProfileInfo = new UserProfileInfo { ImageSize = 0, FileName = null, ImageData = 0 };
//}
public string HomeTown { get; set; }
public virtual UserProfileInfo UserProfileInfo { get; set; }
and this is my userProfileInfo class where i want to save every user's profile pic after they have completed the registration----
public class UserProfileInfo
{
// [Key, ForeignKey("ApplicationUser")]
[Key]
public int Id { get; set; }
public int ImageSize { get; set; }
public string FileName { get; set; }
public byte[] ImageData { get; set; }
[ForeignKey("Id")]
public virtual ApplicationUser ApplicationUser { get; set; }
}
and this is my DbContext class -----
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfileInfo> UserProfileInfo { get; set; }
Now, the problem is that i am unable to configure one to one relationship between ApplicationUser class and UserProfileInfo class.I have tried various ways to do it and followed some stack overflow questions previosly asked But after i had completed my registration form, it states error------
Unable to determine the principal end of an association between the types 'CodeFirstContext.ApplicationUser' and 'CodeFirstContext.UserProfileInfo'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
i have also tried to put relationship with the help of fluent api-----
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// base.OnModelCreating(modelBuilder);
//// Configure Id as PK for UserProfileInfo class
modelBuilder.Entity<UserProfileInfo>()
.HasKey(e => e.Id);
// Configure Id as FK for UserProfileInfo
modelBuilder.Entity<ApplicationUser>()
.HasOptional(s => s.UserProfileInfo)
.WithRequired(ad => ad.ApplicationUser);
}
This way i also failed.Please suggest me how to configure it.