示例#1
0
        ColumnDefinition AddColumn(PropertyInfo pi, ColumnOptionsAttribute attr)
        {
            DbType type;
            var    tp       = pi.PropertyType;
            var    asString = pi.GetSingleAttribute <InsertAsStringAttribute>();

            if (asString != null)
            {
                type = DbType.String;
            }
            else
            {
                if (tp.IsEnum)
                {
                    tp = Enum.GetUnderlyingType(tp);
                }
                type = FromType(tp);
            }



            var col = new ColumnDefinition();

            col.Name         = pi.Name;
            col.DefaultValue = attr.DefaultValue;
            col.IsIdentity   = (_ti.PrimaryKey == col.Name && _ti.AutoGenerated == true);
            col.Size         = attr.Size;
            col.Type         = type;
            if (pi.PropertyType.IsNullable())
            {
                col.IsNullable = true;
            }
            else
            {
                col.IsNullable = attr.IsNullable;
            }
            _schema.Columns.AddColumn(col);
            return(col);
        }
示例#2
0
        private ColumnDefinition AddColumn(PropertyInfo pi, ColumnOptionsAttribute attr)
        {
            DbType type;
            var tp = pi.PropertyType;
            var asString = pi.GetModelAttributes<InsertAsStringAttribute>().FirstOrDefault();
            if (asString != null)
            {
                type = DbType.String;
            }
            else
            {
                if (tp.IsEnum)
                {
                    tp = Enum.GetUnderlyingType(tp);
                }
                type = FromType(tp);
            }


            var col = new ColumnDefinition();
            col.Name = pi.Name;
            col.DefaultValue = attr.DefaultValue;
            col.IsIdentity = (_ti.PrimaryKey == col.Name && _ti.AutoGenerated);
            col.Size = attr.Size;
            col.Type = type;
            if (pi.PropertyType.IsNullable())
            {
                col.IsNullable = true;
            }
            else
            {
                col.IsNullable = attr.IsNullable;
            }
            _schema.Columns.AddColumn(col);
            return col;
        }