|
-
Nov 25th, 2011, 12:44 AM
#1
Thread Starter
Randalf the Red
Entities Framework and Relationship Tables
I am struggling with mapping many to many relationships between more than two tables in ADO.Net Entities Framework.
I am using DotNet 3.5 with VS 2008. All my tables are mapped to entities through the ADO.Net Entities Framework. I had a hard time figuring out how to map many to many relationships between two tables, but by searching on the net I was able to figure out the solution.
Now I have a more complex scenario where there are three tables in a many to many relationship. Here's a rough model:
There are groups, with a GroupID as PK.
There are access rights, with an AccessRightID as PK.
There are users, with a UserID as PK.
Each user can belong to many groups and have many access rights within each group. The table designed to hold this relationship has just three fields:
GroupID
AccessRightID
UserID
All three not null and are FK to the respective table PKs.
If this were a table with just two fields, Entities Framework would automatically create relationships from this table. However with three fields, EF creates a separate entity for this table, which is not what I want.
Any solution?
.
-
Nov 25th, 2011, 02:44 AM
#2
Re: Entities Framework and Relationship Tables
You have no choice but to have a separate entity. Think about it. If you have a Group then it could have a collection of Users but that would not say anything about what AccessRights those users have in that group. You have no choice but to have an entity that knows about all three at the same time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|