I'm using EF 6.1.1 and the latest Data Tools for VS 2013.
Some of my entities are defined with optional relationships. Using the (now obsolete) Reverse Engineering power tool it would generate the proper relationship metadata:
Some of my entities are defined with optional relationships. Using the (now obsolete) Reverse Engineering power tool it would generate the proper relationship metadata:
public class PersonLanguageOtherCodeMap : EntityTypeConfiguration<PersonLanguageOtherCode>
{
public PersonLanguageOtherCodeMap()
{
...
// Relationships
this.HasRequired(t => t.PersonLanguage)
.WithOptional(t => t.PersonLanguageOtherCode);
}
}
When I used the new "Code First From Database" option, it generates the following POCO classes: [Table("PersonLanguageOtherCode")]
public partial class PersonLanguageOtherCode:EntityBase
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public long PersonLanguageId { get; set; }
[Required]
[StringLength(50)]
public string OtherCode { get; set; }
[StringLength(100)]
public string CodeSetName { get; set; }
public short StatusId { get; set; }
[Required]
[StringLength(50)]
public string CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
[StringLength(50)]
public string ModifiedBy { get; set; }
public DateTime? ModifiedDate { get; set; }
public virtual PersonLanguage PersonLanguage { get; set; }
}
and when I attempt to load the context, I get the following error:
System.InvalidOperationException: Unable to determine the principal end of an association between the types 'Education.EntityStorage.Live.Entities.PersonLanguageOtherCode' and 'Education.EntityStorage.Live.Entities.PersonLanguage'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
How can I get the data tool to properly set my optional relationships?