Results 1 to 2 of 2

Thread: Entities Framework and Relationship Tables

  1. #1

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    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?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width