Exemplo n.º 1
0
        public static DataTable DeriveSchemaTable(FeatureDataTable table,
                                                  ColumnLengthComputationDelegate lengthComputationDelegate,
                                                  ColumnPrecisionComputationDelegate precisionComputationDelegate,
                                                  ColumnScaleComputationDelegate scaleComputationDelegate)
        {
            DataTable schema = CreateSchemaTable();

            foreach (DataColumn column in table.Columns)
            {
                DataColumn[] keyColumns = table.PrimaryKey ?? new DataColumn[] { };

                Int32 length = column.ExtendedProperties.ContainsKey(LengthExtendedProperty)
                    ? Convert.ToInt32(column.ExtendedProperties[LengthExtendedProperty])
                    : (lengthComputationDelegate == null) ? 0 : lengthComputationDelegate(column);

                Int16 precision = column.ExtendedProperties.ContainsKey(NumericPrecisionExtendedProperty)
                    ? Convert.ToInt16(column.ExtendedProperties[NumericPrecisionExtendedProperty])
                    : (precisionComputationDelegate == null) ? (Int16)0 : precisionComputationDelegate(column);

                Int16 scale = column.ExtendedProperties.ContainsKey(NumericScaleExtendedProperty)
                    ? Convert.ToInt16(column.ExtendedProperties[NumericScaleExtendedProperty])
                    : (scaleComputationDelegate == null) ? (Int16)0 : scaleComputationDelegate(column);

                schema.Rows.Add(
                    column.ColumnName,
                    length,
                    column.Ordinal,
                    precision,
                    scale,
                    column.DataType,
                    column.AllowDBNull,
                    column.ReadOnly,
                    column.Unique,
                    Array.Exists(keyColumns, delegate(DataColumn col) { return(col == column); }),
                    column.AutoIncrement,
                    false);
            }

            return(schema);
        }
        public static DataTable DeriveSchemaTable(FeatureDataTable table,
            ColumnLengthComputationDelegate lengthComputationDelegate,
            ColumnPrecisionComputationDelegate precisionComputationDelegate,
            ColumnScaleComputationDelegate scaleComputationDelegate)
        {
            DataTable schema = CreateSchemaTable();
            foreach (DataColumn column in table.Columns)
            {
                DataColumn[] keyColumns = table.PrimaryKey ?? new DataColumn[] { };

                int length = column.ExtendedProperties.ContainsKey(LengthExtendedProperty)
                    ? Convert.ToInt32(column.ExtendedProperties[LengthExtendedProperty])
                    : (lengthComputationDelegate == null) ? 0 : lengthComputationDelegate(column);

                short precision = column.ExtendedProperties.ContainsKey(NumericPrecisionExtendedProperty)
                    ? Convert.ToInt16(column.ExtendedProperties[NumericPrecisionExtendedProperty])
                    : (precisionComputationDelegate == null) ? (short)0 : precisionComputationDelegate(column);

                short scale = column.ExtendedProperties.ContainsKey(NumericScaleExtendedProperty)
                    ? Convert.ToInt16(column.ExtendedProperties[NumericScaleExtendedProperty])
                    : (scaleComputationDelegate == null) ? (short)0 : scaleComputationDelegate(column);

#if !CFBuild
                schema.Rows.Add(
                    column.ColumnName,
                    length,
                    column.Ordinal,
                    precision,
                    scale,
                    column.DataType,
                    column.AllowDBNull,
                    column.ReadOnly,
                    column.Unique,
                    Array.Exists(keyColumns, delegate(DataColumn col) { return col == column; }),
                    column.AutoIncrement,
                    false);
#else //The Predicate is a delegate to a method that returns true if the object passed to it
                //matches the conditions defined in the delegate. The elements of array are individually 
                //passed to the Predicate, and processing is stopped when a match is found.
                bool isKey = false;
                foreach (DataColumn col in keyColumns)
                {
                    if (col == column)
                    {
                        isKey = true;
                        break;
                    }
                }

                schema.Rows.Add(
                    column.ColumnName,
                    length,
                    column.Ordinal,
                    precision,
                    scale,
                    column.DataType,
                    column.AllowDBNull,
                    column.ReadOnly,
                    column.Unique,
                    isKey,
                    column.AutoIncrement,
                    false);
#endif
            }

            return schema;
        }
        public static DataTable DeriveSchemaTable(FeatureDataTable table,
            ColumnLengthComputationDelegate lengthComputationDelegate,
            ColumnPrecisionComputationDelegate precisionComputationDelegate,
            ColumnScaleComputationDelegate scaleComputationDelegate)
        {
            DataTable schema = CreateSchemaTable();
            foreach (DataColumn column in table.Columns)
            {
                DataColumn[] keyColumns = table.PrimaryKey ?? new DataColumn[] { };

                Int32 length = column.ExtendedProperties.ContainsKey(LengthExtendedProperty)
                    ? Convert.ToInt32(column.ExtendedProperties[LengthExtendedProperty])
                    : (lengthComputationDelegate == null) ? 0 : lengthComputationDelegate(column);

                Int16 precision = column.ExtendedProperties.ContainsKey(NumericPrecisionExtendedProperty)
                    ? Convert.ToInt16(column.ExtendedProperties[NumericPrecisionExtendedProperty])
                    : (precisionComputationDelegate == null) ? (Int16)0 : precisionComputationDelegate(column);

                Int16 scale = column.ExtendedProperties.ContainsKey(NumericScaleExtendedProperty)
                    ? Convert.ToInt16(column.ExtendedProperties[NumericScaleExtendedProperty])
                    : (scaleComputationDelegate == null) ? (Int16)0 : scaleComputationDelegate(column);

                schema.Rows.Add(
                    column.ColumnName,
                    length,
                    column.Ordinal,
                    precision,
                    scale,
                    column.DataType,
                    column.AllowDBNull,
                    column.ReadOnly,
                    column.Unique,
                    Array.Exists(keyColumns, delegate(DataColumn col) { return col == column; }),
                    column.AutoIncrement,
                    false);
            }

            return schema;
        }