Beispiel #1
0
        public override object Clone()
        {
            var constraint = new DBConstraint()
            {
                Name   = Name,
                Type   = Type,
                Column = Column,
                Value  = Value,
            };

            foreach (var item in Columns)
            {
                constraint.Columns.Add(item.Clone());
            }
            return(constraint);
        }
Beispiel #2
0
        public override void InsertInternal(int index, T item)
        {
            if (Contains(item))
            {
                return;
            }
            if (Contains(item.Name))
            {
                throw new InvalidOperationException($"Columns name duplication {item.Name}");
            }
            // if (col.Order == -1 || col.Order > this.Count)
            if (item.IsPrimaryKey && index > 1)
            {
                index = 1;
            }
            if (item.IsTypeKey)
            {
                index = 0;
            }
            item.Order = index;

            base.InsertInternal(index, item);

            if (item.IsPrimaryKey)
            {
                DBConstraint primary = null;
                foreach (var constraint in Table.Constraints.GetByColumn(Table.PrimaryKey))
                {
                    if (constraint.Type == DBConstraintType.Primary)
                    {
                        primary = constraint;
                        break;
                    }
                }
                if (primary == null && Table.PrimaryKey != null)
                {
                    primary = new DBConstraint()
                    {
                        Column = Table.PrimaryKey, Type = DBConstraintType.Primary
                    };
                    primary.GenerateName();
                    Table.Constraints.Add(primary);
                    //Table.DefaultComparer = item.CreateComparer(); Commented for poerformance of Index creation
                }
            }
            item.CheckPull();
        }