Пример #1
0
 /// <summary>
 /// 进行sql数据库类型和.Net CLR 之间类型的转换。
 /// </summary>
 /// <param name="col">The col.</param>
 /// <returns></returns>
 public static string ExchangeDotNetType(Column col)
 {
     string dotNetType = "string";
     switch (col.DataType.ToLowerInvariant())
     {
         case "smallint":
         case "int":
             dotNetType = col.Nullable.ToBoolean() ? "int?" : "int";
             break;
         case "datetime":
             dotNetType = col.Nullable.ToBoolean() ? "DateTime?" : "DateTime";
             break;
         case "float":
             dotNetType = col.Nullable.ToBoolean() ? "float?" : "float";
             break;
         case "decimal":
             dotNetType = col.Nullable.ToBoolean() ? "decimal?" : "decimal";
             break;
         case "timestamp":
             dotNetType = "byte[]";
             break;
         case "bit":
             dotNetType = col.Nullable.ToBoolean() ? "bool?" : "bool";
             break;
         case "uniqueidentifier":
             dotNetType = "Guid";
             break;
         case "tinyint":
             dotNetType = col.Nullable.ToBoolean() ? "Int16?" : "Int16";
             break;
         case "varchar":
         case "char":
         case "nvarchar":
         case "nchar":
         case "text":
         case "demo":
         default:
             break;
     }
     return dotNetType;
 }
Пример #2
0
        /// <summary>
        /// 生成构造函数以及内部部分
        /// </summary>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        private string buildCtor(Column column)
        {
            string defValue = column.DefaultValue.Replace("(", string.Empty).Replace(")", string.Empty);
            string datatypeLower = column.DataType.ToLowerInvariant();
            if (t_Sql_Func.Contains(datatypeLower))
            {
                defValue = "DateTime.Now";
            }
            else if (t_ints.Contains(datatypeLower)) //int ..
            {
                if (datatypeLower == "bit")
                    defValue = defValue.Replace("0", "false").Replace("1", "true");
                else
                    defValue = column.DefaultValue;
            }
            else if (t_strings.Contains(datatypeLower))//string 
            {
                defValue = "\"{0}\"".FormatWith(defValue);
            }
            /*
             
             ID = 1;
             {0} = {1} ;
             */

            return "_{0} = {1} ; ".FormatWith(column.ColumnName, defValue);
        }