/// <summary>
        /// Returns a prepared collection of restrictions
        /// </summary>
        /// <param name="constraints">List of raw constraints</param>
        /// <param name="options">List of raw cascade options</param>
        /// <returns>The filtered list of constraints of the table</returns>
        private List <DtoConstraint> ConstraintsCollectionPreparation(IEnumerable <MySqlConstaintsModel> constraints, IEnumerable <MySqlCascadeOption> options)
        {
            List <DtoConstraint> dtoConstraints = new List <DtoConstraint>();

            foreach (var cons in constraints)
            {
                DtoConstraint item = new DtoConstraint
                {
                    FieldName      = cons.COLUMN_NAME,
                    ConstraintType = cons.CONSTRAINT_TYPE,
                    ConstraintName = cons.CONSTRAINT_NAME == "PRIMARY" ? $"PR_{cons.COLUMN_NAME}" : cons.CONSTRAINT_NAME,
                    Referenced     = ReferencedStringDecoration(cons.REFERENCED_TABLE_NAME, cons.REFERENCED_COLUMN_NAME)
                };
                dtoConstraints.Add(item);
            }

            foreach (var option in options)
            {
                var result = dtoConstraints.FirstOrDefault(o => o.ConstraintName == option.CONSTRAINT_NAME);
                if (result != null)
                {
                    result.OnUpdate = option.UPDATE_RULE;
                    result.OnDelete = option.DELETE_RULE;
                }
            }

            return(dtoConstraints);
        }
Example #2
0
        /// <summary>
        /// Returns a prepared collection of restrictions
        /// </summary>
        /// <param name="constraints">List of raw constraints</param>
        /// <returns>The filtered list of constraints of the table</returns>
        private List <DtoConstraint> ConstraintsCollectionPreparation(IEnumerable <DtoConstraint> constraints)
        {
            List <DtoConstraint> consts = new List <DtoConstraint>();

            foreach (var constraint in constraints)
            {
                DtoConstraint tempConsts = new DtoConstraint();

                var type = constraint.ConstraintType.Split(' ');
                tempConsts.ConstraintName = constraint.ConstraintName;
                tempConsts.OnDelete       = constraint.OnDelete;
                tempConsts.OnUpdate       = constraint.OnUpdate;

                if (type[0] == "CHECK" || type[0] == "DEFAULT")
                {
                    tempConsts.ConstraintType = type[0];
                    tempConsts.FieldName      = type[type.Length - 1];
                    tempConsts.ConstraintKeys = constraint.ConstraintKeys;
                }
                else if (type[0] == "PRIMARY" || type[0] == "FOREIGN")
                {
                    tempConsts.ConstraintType = constraint.ConstraintType;
                    tempConsts.FieldName      = constraint.ConstraintKeys;
                }
                else if (constraint.ConstraintKeys.Split(' ')[0] == "REFERENCES")
                {
                    var last = consts.Last();
                    last.Referenced = constraint.ConstraintKeys.Replace("REFERENCES ", "");
                    continue;
                }
                else
                {
                    tempConsts.ConstraintType = constraint.ConstraintType;
                    tempConsts.FieldName      = constraint.ConstraintKeys;
                }
                consts.Add(tempConsts);
            }
            return(consts);
        }