I need to configure a relation with following classes: User have or not a profile. Structure: User: UserID, Username, Password Profile: UserID, FullName, Address, Phone
public class User
{
#region Feilds
public int UserID { get; set; }
public string Email { get; set; }
public string Password { get; set; }
#endregion
public virtual Profile Profile { get; set; }
}
public class Profile
{
#region Fields
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
#endregion
public virtual User User { get; set; }
}
Configuration:
public class UserConfiguration : EntityTypeConfiguration<User>
{
public UserConfiguration()
: base()
{
// Primary Key
this.HasKey(p => p.UserID);
//Foreign Key
this.HasOptional(p => p.Profile).
WithMany().
HasForeignKey(p => p.UserID);
}
}
Error:
System.Data.Edm.EdmEntityType: : EntityType 'Profile' has no key defined. Define the key for this EntityType. System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Profiles� is based on type �Profile� that has no keys defined.
Please help.
Thanks.