EF codeFirst generation error
-
I'm beginner on EntityFramework Core Code first database generation and I have a problem with relation configuration of two entities :
public class EntityParent
{
public int Id { get; set; }
public string Name { get; set; }
//Navigation properties to the EntityChildren which have info of start position.
[ForeignKey("TransformationEntity")]
public int? TransformationEntityId { get; set; }
public virtual EntityChildren TransformationEntity { get; set; }
//Navigation property : List of childrens
public virtual ICollection Childrens { get; set; }
}
public class EntityChildren
{
public int Id { get; set; }
public string Name { get; set; }
public int StartPosition { get; set; }
//List of EntityParents which have this EntityChildren as the start position
public virtual ICollection TransformedParents { get; set; }
//Relation one-to-one(this same table)
[ForeignKey("EntityChildrenSource")]
public int? Cadrage { get; set; }
public virtual EntityChildren EntityChildrenSource { get; set; }
public virtual EntityChildren EntityChildrenTarget { get; set; }
//Navigation property to EntityParent
[ForeignKey("Parent")]
public int Parent_FK { get; set; }
public virtual EntityParent Parent { get; set; }
}The goal is to have in the EntityParent the properties : - List of childrens. - The EntityChildren that contains Start position. And in the EntityChildren the properties : - List of EntityParent which have this entity as start position - The EntityParent of this EntityChildren - The EntityChildrenSource - The EntityChildrenTarget BUT when executing the command to generate scripts of database I have the error bellow : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Unable to det ermine the relationship represented by navigation property 'EntityChildren.TransformedParents' of type 'ICollection'. Either manually configu re the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'. at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder) at Microsoft.EntityFrameworkCore.Metadata.Conventi