コード例 #1
0
ファイル: DatabaseView.cs プロジェクト: fagan2888/Schematic
        /// <summary>
        /// Initializes a new instance of the <see cref="DatabaseView"/> class.
        /// </summary>
        /// <param name="viewName">The view name.</param>
        /// <param name="definition">The view definition.</param>
        /// <param name="columns">An ordered collection of columns defined by the view definition.</param>
        /// <exception cref="ArgumentNullException"><paramref name="viewName"/> is <c>null</c>, or <paramref name="definition"/> is <c>null</c>, empty, or whitespace, or <paramref name="columns"/> is <c>null</c> or contains <c>null</c> values.</exception>
        public DatabaseView(
            Identifier viewName,
            string definition,
            IReadOnlyList <IDatabaseColumn> columns
            )
        {
            if (definition.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(definition));
            }
            if (columns == null || columns.AnyNull())
            {
                throw new ArgumentNullException(nameof(columns));
            }

            Name       = viewName ?? throw new ArgumentNullException(nameof(viewName));
            Columns    = columns;
            Definition = definition;
        }
コード例 #2
0
        public Concat(IEnumerable <Entity> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }


            EntityCollection = new List <Entity>(entities).AsReadOnly();

            if (EntityCollection.AnyNull())
            {
                throw new ArgumentException("There are null items in collection.");
            }

            if (EntityCollection.Count < 2)
            {
                throw new ArgumentException("Concat must have at least two items.");
            }

            _Variables = new Lazy <IReadOnlySet <Variable> >(() => CollectVariables(EntityCollection));
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RelationalDatabaseTable"/> class.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="columns">The columns.</param>
        /// <param name="primaryKey">The primary key.</param>
        /// <param name="uniqueKeys">The unique keys.</param>
        /// <param name="parentKeys">The parent keys.</param>
        /// <param name="childKeys">The child keys.</param>
        /// <param name="indexes">The indexes.</param>
        /// <param name="checks">The checks.</param>
        /// <param name="triggers">The triggers.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="tableName"/> or <paramref name="columns"/> or <paramref name="uniqueKeys"/> or <paramref name="parentKeys"/> or <paramref name="childKeys"/> or <paramref name="indexes"/> or <paramref name="checks"/> or <paramref name="triggers"/>.
        /// If a given collection contains a <c>null</c> value, an <see cref="ArgumentNullException"/> will also be thrown.
        /// </exception>
        /// <exception cref="ArgumentException">When given key with mismatching key types, e.g. primary key or unique keys.</exception>
        public RelationalDatabaseTable(
            Identifier tableName,
            IReadOnlyList <IDatabaseColumn> columns,
            Option <IDatabaseKey> primaryKey,
            IReadOnlyCollection <IDatabaseKey> uniqueKeys,
            IReadOnlyCollection <IDatabaseRelationalKey> parentKeys,
            IReadOnlyCollection <IDatabaseRelationalKey> childKeys,
            IReadOnlyCollection <IDatabaseIndex> indexes,
            IReadOnlyCollection <IDatabaseCheckConstraint> checks,
            IReadOnlyCollection <IDatabaseTrigger> triggers)
        {
            if (columns == null || columns.AnyNull())
            {
                throw new ArgumentNullException(nameof(columns));
            }
            if (uniqueKeys == null || uniqueKeys.AnyNull())
            {
                throw new ArgumentNullException(nameof(uniqueKeys));
            }
            if (parentKeys == null || parentKeys.AnyNull())
            {
                throw new ArgumentNullException(nameof(parentKeys));
            }
            if (childKeys == null || childKeys.AnyNull())
            {
                throw new ArgumentNullException(nameof(childKeys));
            }
            if (indexes == null || indexes.AnyNull())
            {
                throw new ArgumentNullException(nameof(indexes));
            }
            if (checks == null || checks.AnyNull())
            {
                throw new ArgumentNullException(nameof(checks));
            }
            if (triggers == null || triggers.AnyNull())
            {
                throw new ArgumentNullException(nameof(triggers));
            }

            primaryKey.IfSome(pk =>
            {
#pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
                if (pk.KeyType != DatabaseKeyType.Primary)
                {
                    throw new ArgumentException("The given primary key did not have a key type of '" + nameof(DatabaseKeyType.Primary) + "'", nameof(primaryKey));
                }
#pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
            });

            var anyNonUniqueKey = uniqueKeys.Any(uk => uk.KeyType != DatabaseKeyType.Unique);
            if (anyNonUniqueKey)
            {
                throw new ArgumentException("A given unique key did not have a key type of '" + nameof(DatabaseKeyType.Unique) + "'", nameof(uniqueKeys));
            }

            Name       = tableName ?? throw new ArgumentNullException(nameof(tableName));
            Columns    = columns;
            PrimaryKey = primaryKey;
            UniqueKeys = uniqueKeys;
            ParentKeys = parentKeys;
            ChildKeys  = childKeys;
            Indexes    = indexes;
            Checks     = checks;
            Triggers   = triggers;
        }