internal static SqlUserGranting Create(SqlPermission arg, string dbName)
            {
                string target =
                    arg.class_desc + (
                        String.Equals(arg.class_desc, "DATABASE", StringComparison.OrdinalIgnoreCase) ?
                        "" :
                        (":" + arg.object_name)
                        );


                return(new SqlUserGranting()
                {
                    Database = dbName,
                    Name = arg.name,
                    Sid = arg.sid_string,
                    Type = GrantingType.Grant,
                    Target = target,
                    Permission = arg.permission_name
                });
            }
 internal void AddPermission(SqlPermission permission)
 {
     if (!this.permissions.Contains(permission))
     {
         this.permissions.Add(permission);
     }
 }
        public static IAccessStatement GenerateBaseGrant(
            string database,
            SqlPermission permission,
            string parentName,
            string objectName,
            phPrincipal principal,
            string statement)
        {
            var gas = new GenericAccessStatement
                {
                    // GRANT
                    AccessType = AccessType.Grant,
                    // Database name
                    Database = database,
                    // On a specific object
                    SecurableObject = String.IsNullOrWhiteSpace(objectName) ? null : new SecurableObject
                    {
                        Type = permission.PermissionClass,
                        Database = database,
                        ObjectOwner = parentName,
                        ObjectName = objectName
                    }
                };

            // A set of permissions
            gas.AddPermission(permission);

            // To a set of users
            gas.AddPrincipal(principal);

            // Additional meta-data
            gas.AddStatement(statement);

            return gas;
        }