I have defined three database tables:
- User (UserId, Username),
- Role (RoleId, RoleName)
- UserRoles (UserId, RoleId)
When Telerik ORM imports the tables into a model it does not create an entity for UserRoles. I believe this is because it is deemed to be a join table?
As a result of this I'm given to understand that the only way to create a UserRole would be to either add a User to the Role.Users list or add a Role to the User.Roles list.
In theory this sounds fine but I have come concerns. It would the ORM layer will execute 4 seperate sql statements when I want to create a single record. Here is my code and reasoning:
'Define the context
'Get the user entity
user = (From u
portal.Users Where u.UserId = UserId
'SQL CALL #1
'Get the role entity
role = (From r
portal.Roles Where r.RoleId = RoleId
'SQL CALL #2
'Add the role to the user (insert the record)
'SQL CALL #3
'Save the changes
'SQL CALL #4
Is there a way to simply create a UserRole record without having to fetch the user, role, user roles and then finally insert the record?