EF 4.0 Self Referencing Many-To-Many relationship with Additional attribute
I'm using EF 4.0 and was able to create self referencing many to many relationship. Person and family members. What I also want is to add additional attribute like 'mother', 'brother', 'sister' for each relationship. At the database level, this model generates two tables. Person and PersonRelationship. PersonRelationship table has person_id, and relative_id as PK. I like to have another column relationshiptype in PersonRelationship table 开发者_Go百科and reference in EF 4.0. Please let me know how to do it if you don't mind?
If I were you I would create a table "RelationshipTypes". It holds the different possible types of relationship for you. Just two columns ID and Name of relationship.
Second you just add the RelationshipTypeID to your PersonRelationship and mark it as primary key too.
You should have then three primary keys in your table. Just update your model in Visual Studio and it should work.
Does this help?
Regards Thomas
精彩评论