Пример #1
0
        private static void Attribute(AttributeInfo attr, IColumn column)
        {
            List<string> args = new List<string>();
            string _columnName = column.ToFieldName();
            args.Add($"_{_columnName}");
            args.Add($"CType.{column.CType}");

            switch (column.CType)
            {
                case CType.VarBinary:
                case CType.Binary:
                    args.Add(string.Format("Length = {0}", column.AdjuestedLength()));
                    break;

                case CType.Char:
                case CType.VarChar:
                case CType.NChar:
                case CType.NVarChar:
                    int len = column.AdjuestedLength();
                    if (len != -1)
                        args.Add(string.Format("Length = {0}", len));
                    break;

                //case CType.Numeric:
                case CType.Decimal:
                    args.Add($"Precision = {column.Precision}");
                    args.Add($" Scale = {column.Scale}");
                    break;
            }

            if (column.Nullable)
                args.Add("Nullable = true");   //see: bool Nullable = false; in class DataColumnAttribute

            if (column.IsIdentity)
                args.Add("Identity = true");

            if (column.IsPrimary)
                args.Add("Primary = true");

            if (column.IsComputed)
                args.Add("Computed = true");

            attr.args = args.ToArray();
        }
Пример #2
0
        /// <summary>
        /// [TableName.Level] is not updated in [this.tname], then parameter [level] must be passed in
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        internal static void GetTableAttribute(AttributeInfo attr, ITable metaTable, ClassTableName ctname)
        {
            attr.comment = new Comment(string.Format("Primary Keys = {0};  Identity = {1};", metaTable.PrimaryKeys, metaTable.Identity));

            List<string> args = new List<string>();

            TableName tableName = metaTable.TableName;
            switch (ctname.Option.Level)
            {

                case Level.Application:
                    args.Add($"\"{tableName.Name}\"");
                    args.Add("Level.Application");
                    break;

                case Level.System:
                    args.Add($"\"{tableName.Name}\"");
                    args.Add("Level.System");
                    break;

                case Level.Fixed:
                    args.Add($"\"{tableName.DatabaseName.Name}\"");
                    args.Add("Level.Fixed");
                    break;
            }

            if (ctname.Option.HasProvider)
            {
                if (!tableName.Provider.Equals(ConnectionProviderManager.DefaultProvider))
                {

                    args.Add(string.Format("Provider = {0}", (int)tableName.Provider));
                }
            }

            if (!ctname.Option.IsPack)
                args.Add("Pack = false");

            attr.args = args.ToArray();
            return;
        }