First, sorry for my english.
Second, I’m not good at database modeling, so I might be completely wrong.
I’m writing a website (think of it as a forum), where in every post, each user can have a different roles.
The way I would do it without using entity framework is creating 3 tables:
- User
- Group
- Role
- UserGroupRole
Where UserGroupRole would contain the keys for the 3 tables.
How can I do it with entity framework?
Maybe the whole aproach is incorrect, I’m not sure.
Thanks in advance!
Yes, I would probably also work with 4 entities and tables. In EF 4.1 something along these lines:
The foreign key properties enforce all three relationships to be required (
nullis not allowed) and the complex key over all three Ids ensure that any combination of user, group and role can only exist once. You can remove some of the navigation collections – for example inGroupandRole– if you don’t need them.