Example #1
0
        public static column Setup(this column column, MemberInfo memberInfo, string columnName = null, string columnPrefix = "", bool? notnull = true)
        {
            column.SetName(columnName ?? column.GetName() ?? memberInfo.Name.Sanitise(), columnPrefix);

            if (memberInfo.ReturnType() == typeof(string))
            {
                var stringLengthAttribute = memberInfo.GetCustomAttributes(true).OfType<StringLengthAttribute>().SingleOrDefault();
                string maxLength = stringLengthAttribute == null ? SqlDialect.Current.VarcharMax : stringLengthAttribute.MaximumLength.ToString();
                column.sqltype = "NVARCHAR(" + maxLength + ")";
            }
            if (memberInfo.ReturnType() == typeof(byte[]))
            {
                column.sqltype = "VARBINARY(MAX)";
            }

            column.notnull = notnull;

            return column;
        }
Example #2
0
        private static SqlColumnType _getSqlType(MemberInfo mi)
        {
            // See if there's any SqlTypeAttribute on the mi
            // If so, pull the info from there.
            var att = mi.GetCustomAttributes(typeof(SqlTypeAttribute), true)
                .FirstOr(new SqlTypeAttribute()) as SqlTypeAttribute;

            var baseType = SqlTypeConversion.GetSqlType(mi.ReturnType());

            // For anything that's missing, get the assumed type info
            var res = new SqlColumnType(
                att.Type ?? baseType.SqlType,
                att.IsNullable ?? baseType.IsNullable,
                att.Length ?? baseType.Length,
                att.Precision ?? baseType.Precision,
                att.Scale ?? baseType.Scale);

            return res;
        }