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