コード例 #1
0
ファイル: Column.cs プロジェクト: CalvinMann/SimpleSqliteAPI
 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);
        }
コード例 #5
0
 public bool HasForeignKeyTo(string tableName)
 {
     return(!string.IsNullOrEmpty(tableName) && HasForeignKeys && ForeignKeys.Any(x => !string.IsNullOrEmpty(x.FKTableName) && x.FKTableName.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)));
 }