Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. EF codeFirst generation error

EF codeFirst generation error

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpasp-netdatabasequestionlearning
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrKBA
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups