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. LINQ
  4. EF same table (Id, ParentId) model

EF same table (Id, ParentId) model

Scheduled Pinned Locked Moved LINQ
databasexmlhelp
4 Posts 2 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.
  • C Offline
    C Offline
    cechode
    wrote on last edited by
    #1

    Given table People With columns personId identity personType int personParentID int personName varchar details xml ….. I created three entities Abstract people Parent (inherits from people) (personType=1) Children (inherits from people) (personType=2) I want to add a navigational property to the Parent entity of type (Collection of Children) Where the child personParentID equals the parent personID Been trying and looking up for a few hours now and coming up short. Any help would be greatly appreciated p.s (before you hang me for a repost) no answers on the db forum so deleted there and reposted here

    J 1 Reply Last reply
    0
    • C cechode

      Given table People With columns personId identity personType int personParentID int personName varchar details xml ….. I created three entities Abstract people Parent (inherits from people) (personType=1) Children (inherits from people) (personType=2) I want to add a navigational property to the Parent entity of type (Collection of Children) Where the child personParentID equals the parent personID Been trying and looking up for a few hours now and coming up short. Any help would be greatly appreciated p.s (before you hang me for a repost) no answers on the db forum so deleted there and reposted here

      J Offline
      J Offline
      Jon Rista
      wrote on last edited by
      #2

      A navigational property is intrinsically linked to an association. Create an association between Parent and Child, and you will get navigational properties on both entities.

      C 1 Reply Last reply
      0
      • J Jon Rista

        A navigational property is intrinsically linked to an association. Create an association between Parent and Child, and you will get navigational properties on both entities.

        C Offline
        C Offline
        cechode
        wrote on last edited by
        #3

        there's my problem tried having both personId and personParentID be entity keys located in the person entity, and then i could not seem to map the association between a (parent:person) and (child:person) map to child.parentid = parent.personid. also tried removing the personParentID from the person entity and only adding it to the child:person entity, but even then i could not map the association. i guess what i'm saying it that i understand your comment and proposed solution, just don't know how to implement it correctly any pointers would be greatly appreciated.

        J 1 Reply Last reply
        0
        • C cechode

          there's my problem tried having both personId and personParentID be entity keys located in the person entity, and then i could not seem to map the association between a (parent:person) and (child:person) map to child.parentid = parent.personid. also tried removing the personParentID from the person entity and only adding it to the child:person entity, but even then i could not map the association. i guess what i'm saying it that i understand your comment and proposed solution, just don't know how to implement it correctly any pointers would be greatly appreciated.

          J Offline
          J Offline
          Jon Rista
          wrote on last edited by
          #4

          You can't have both a navigation property and the key property in the entity. EF is currently limited to having each schema field bound to one and only one property. So, you can either have the scalar properties and join manually, or you can delete any scalar property that is involved in the association from all entities, and have navigation properties. The only conclusion I have as to this is that Microsoft had a truncated timetable within which to release EF, and they had to cut some corners to maintain integrity of entities. To map properly, you would need something like this: PersonEntity =========================== ID (int) Name (string) ParentEntity (PersonEntity) =========================== Children (EntitySet) ChildEntity (PersonEntity) =========================== Parent (EntityRef) ChildParentAssociation =========================== personParentID (PersonEntity; One) ID (ChildEntity; Many)

          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