Exemple #1
0
        /**
         * Given a property we will return the length value that
         * will be appended directly after the SqlDbType name.
         *
         * ie: ```nvarchar(MAX)```
         */
        protected string GetColumnLength(PropertyInfo prop)
        {
            // Check for a custom length attribute
            var sqlLength = prop.GetCustomAttribute <SqlLengthAttribute>();

            if (sqlLength != null)
            {
                return(sqlLength.Value);
            }

            // Grab the SqlDbType
            SqlDbType sqlType;

            if (prop.GetCustomAttribute <SqlTypeAttribute>() != null)
            {
                sqlType = prop.GetCustomAttribute <SqlTypeAttribute>().Value;
            }
            else
            {
                sqlType = TypeMapper.GetDBType(prop.PropertyType);
            }

            // Types that can have the max length
            // option lets give it to them.
            switch (sqlType)
            {
            case SqlDbType.VarChar:
            case SqlDbType.NVarChar:
            case SqlDbType.VarBinary:
                return("(MAX)");

            default:
                return("");
            }
        }
Exemple #2
0
        /**
         * Given a property we will return the name of the SqlDbType.
         */
        protected string GetColumnType(PropertyInfo prop)
        {
            var sqlType = prop.GetCustomAttribute <SqlTypeAttribute>();

            if (sqlType != null)
            {
                return(sqlType.Value.ToString().ToUpper());
            }

            return(TypeMapper.GetDBType(prop.PropertyType).ToString().ToUpper());
        }