I am writing a backend surveys database. The database is the backend for multiple applications that are used for gathering survey type data. I have a schema that includes a table that designates the application and what questions belong to that application.
now I need to setup users and userroles…
each user may have access to 1 or more applications
each application has 1 or more users
each user may have 1 role in the application they have access to
each role may exist in 1 or more applications
each user may have different roles in each application.
app1 has 15 users 1 user is admin
app1 has 2 roles defined for user access
app2 has 30 users admin user from app1 has access but is regular user
2 admin users in app2 exist in app1 as normal users
app2 has 4 roles defined for user access.
WARNING FREE FORM THOUGHT PROCESS
so I have
Application ->ApplicationUsers<-Users
maybe I only need one joining table then like this?

Would that be correct? Would it work in EF 4.0?
What would be the correct way to make this work?
Let’s assume that this
should be punctuated like this.
If that first clause means that each user must have one and no more than one role in each application they have access to, then your schema won’t work. The compound primary key {ApplicationId, UserID, RoleID} in ApplicationUserRoles allows multiple roles per user.
To limit the constraint “one row (and one role) per user per application”, the primary key for ApplicationUserRoles should be just {ApplicationID, UserID}.
Also, if UserID is unique in the table Users, it should probably be the primary key, and you should probably drop the column “ID” from that table.