示例#1
0
 internal void AddToTable(Table table)
 {
     if (table.IsAttached)
     {
         if (!IsNameValid(Name))
         {
             throw new InvalidNameException(Name, Resources.InvalidColumnName.FormatExt(Name));
         }
         if (IsPrimaryKey)
         {
             throw new TableChangeNotSupported(table, this, Resources.CannotAddPrimaryKey.FormatExt(Name));
         }
         if (ForeignKeys.Any())
         {
             throw new TableChangeNotSupported(table, this,
                                               Resources.CannotAddForeignKeyToAttachedTable.FormatExt(Name, table.Name));
         }
         if (!IsNullable && DefaultValue == null)
         {
             throw new InvalidOperationException(Resources.CannotAddNotNullWithoutValue.FormatExt(Name));
         }
         var sql = CreateSql.FormatExt(table.Name, Definition);
         table.Database.Connection.ExecuteNonQuery(sql);
         if (Quantity == ColumnQuantity.List)
         {
             table.Database.Connection.ExecuteNonQuery(CreateListColumnSql.FormatExt(table.Name, Name,
                                                                                     (long)Type));
         }
     }
     Table = table;
 }
示例#2
0
        public override object ToMinified()
        {
            var vs = Validators.Select(v => v.ToMinified()).ToList();

            return(new {
                n = Name,
                r = ResourceName,
                l = GetDisplayName(),
                t = EntityTypeName,
                s = IsScalar == true ? true : (bool?)null,
                a = AssociationName,
                c = DoCascadeDelete == true ? true : (bool?)null,
                f = ForeignKeys.Any() ? ForeignKeys : null,
                v = vs.Any() ? vs : null
            });
        }
示例#3
0
        public virtual void RemoveProperty([NotNull] Property property)
        {
            Check.NotNull(property, "property");

            var currentIndex = _properties.BinarySearch(property, PropertyComparer.Instance);

            if (currentIndex >= 0)
            {
                if (Keys.Any(k => k.Properties.Contains(property)) ||
                    ForeignKeys.Any(k => k.Properties.Contains(property)) ||
                    Indexes.Any(i => i.Properties.Contains(property)))
                {
                    throw new InvalidOperationException(Strings.FormatPropertyInUse(property.Name, Name));
                }

                _properties.RemoveAt(currentIndex);
                UpdateIndexes(property, currentIndex);

                property.EntityType = null;
            }
        }
示例#4
0
        public virtual Property RemoveProperty([NotNull] Property property)
        {
            Check.NotNull(property, "property");

            var currentIndex = _properties.BinarySearch(property, PropertyComparer.Instance);

            if (currentIndex >= 0)
            {
                if (Keys.Any(k => k.Properties.Contains(property)) ||
                    ForeignKeys.Any(k => k.Properties.Contains(property)) ||
                    Indexes.Any(i => i.Properties.Contains(property)))
                {
                    throw new InvalidOperationException(Strings.PropertyInUse(property.Name, Name));
                }

                var removedProperty = _properties[currentIndex];
                _properties.RemoveAt(currentIndex);
                UpdateIndexes(property, currentIndex);

                return(removedProperty);
            }

            return(null);
        }
 public bool HasForeignKeyTo(string tableName)
 {
     return(!string.IsNullOrEmpty(tableName) && HasForeignKeys && ForeignKeys.Any(x => !string.IsNullOrEmpty(x.FKTableName) && x.FKTableName.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)));
 }