static internal RLSFilterExpression Get(ModelRole role, Table table) { RLSFilterExpression result; if (!role.RowLevelSecurity.FilterExpressions.TryGetValue(table, out result)) { result = new RLSFilterExpression(role, table); role.RowLevelSecurity.FilterExpressions.Add(table, result); } return(result); }
protected override void SetValue(Table table, string filterExpression) { var tps = Role.MetadataObject.TablePermissions; var tp = tps.Find(table.Name); // Filter expression removed: if (string.IsNullOrWhiteSpace(filterExpression)) { // Don't do anything if there is no TablePermission for this table anyway: if (tp == null) { return; } // Otherwise, remove the TablePermission: tps.Remove(tp); Handler.UndoManager.Add(new UndoPropertyChangedAction(Role, "RowLevelSecurity", tp.FilterExpression, null, table.Name)); RLSFilterExpression rls; if (FilterExpressions.TryGetValue(table, out rls)) { FormulaFixup.ClearDependsOn(rls); _filterExpressions.Remove(table); } } else // Filter expression assigned: { // Create a new TablePermission if we don't already have one for this table: if (tp == null) { tp = new TOM.TablePermission() { Table = table.MetadataObject }; tps.Add(tp); } // Assign the new expression to the TablePermission: var oldValue = tp.FilterExpression; tp.FilterExpression = filterExpression; Role.Handler.UndoManager.Add(new UndoPropertyChangedAction(Role, "RowLevelSecurity", oldValue, filterExpression, table.Name)); if (!Handler.NameChangeInProgress) { var rls = RLSFilterExpression.Get(Role, table); FormulaFixup.BuildDependencyTree(rls); } } }