Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you create a many-to-many relationship in Entity Framework if the database doesn't have a linking table?
    primarykey
    data
    text
    <p>I am using the VS 2010 Entity Framework designer to modify some of the entities that were auto-generated from a database.</p> <p>The database structure is defined by a product I am building a UI for so I can't modify it.</p> <p>The database has tables that have a many-to-many relationship based purely around common values in non-key columns on both tables.</p> <ul> <li>Table 1 <strong>Users</strong> has a single id column <strong><em>userId</em></strong> and another column called <strong><em>userProfile</em></strong>.</li> <li>Table 2 <strong>SecurityProfile</strong> has a single id column <strong><em>securityProfileId</em></strong> and also has column <strong><em>userProfile</em></strong>.</li> </ul> <p>In other words a User Profile is just a name for a mapping of users to SecurityProfiles.</p> <p>The wizard created entities for both the Users and SecurityProfile tables. I created a new entity called UserProfile with a single key field: <strong>userProfile</strong>.</p> <p>I created a one-to-many association from UserProfile to User and from UserProfile to SecurityProfile. This all works fine except that the UserProfile entity has no table mapping so it won't compile.</p> <p>How do I create this association in Entity Framework?</p> <p><strong>UPDATE:</strong></p> <p>If it's not possible using EF (as is suggested by the first answer), is it possible to manually create a non-bound entity that I can use to link these two entities so that I expose an object model that is at least a little easier to navigate?</p> <p>i.e. I would make the <strong>User</strong> and <strong>SecurityProfile</strong> entities abstract and manually define an extension of these with the appropriate properties pointing to my manually created UserProfile entity</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload