我需要更新安全角色的用户列表。如何避免重新关联已分配角色的用户?
我正在尝试构建一个查询以获取用户 x 不在角色的用户列表中的角色,然后在找不到用户时将其用于关联。这是我到目前为止所拥有的:
LinkEntity userRoles = new LinkEntity
{
LinkFromEntityName = "role",
LinkToEntityName = "systemuserroles",
LinkFromAttributeName = "roleid",
LinkToAttributeName = "roleid",
JoinOperator = JoinOperator.LeftOuter,
Columns = new ColumnSet(true),
EntityAlias = "userroles",
LinkCriteria =
{
Conditions =
{
new ConditionExpression{
//not sure how to build the "where user x does not exists"
}
}
}
};
QueryExpression roleQuery = new QueryExpression
{
EntityName = "role",
ColumnSet = new ColumnSet(true),
Criteria =
{
Conditions = {
new ConditionExpression {
AttributeName = "name",
Operator = ConditionOperator.Equal,
Values = { "RoleName"}
}
}
},
LinkEntities = { userRoles }
};
我需要构建类似这样的查询:
select * from role
where role.name = "RoleName"
and not exists
(select 1 from userRoles
where userRoles.roleid = role.roleid
and userRoles.user = "xyz")