This question is locked. New answers and comments are not allowed.
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:
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?
- 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
Dim
portal
As
New
DbContext
'Get the user entity
Dim
user = (From u
In
portal.Users Where u.UserId = UserId
Select
u).FirstOrDefault
'SQL CALL #1
'Get the role entity
Dim
role = (From r
In
portal.Roles Where r.RoleId = RoleId
Select
r).FirstOrDefault
'SQL CALL #2
'Add the role to the user (insert the record)
user.Roles.Add(role)
'SQL CALL #3
'Save the changes
portal.Add(user)
portal.SaveChanges()
'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?