• 关键词:CodeSmith工具、Money类型、__UNKNOWN__


    问题描述:
     当数据库列类型有Money类型的时候,CodeSmith生成数据访问层会出错。有不能识别的类型。
    解决方法:
     通过查找资料得知,数据库中的Money类型在DbType中是Currency(货币类型),在C#中对应SqlDbType.Decimal。
     ①在
      public string GetCSharpVariableType2(ColumnSchema column)
      {
      if (column.Name.EndsWith("TypeCode")) return column.Name;
     
       switch (column.DataType)
       {
        case DbType.AnsiString: return "SqlDbType.VarChar";
        case DbType.AnsiStringFixedLength: return "SqlDbType.VarChar";
        case DbType.Binary: return "SqlDbType.Binary";
        case DbType.Boolean: return "SqlDbType.Bit";
        case DbType.Date: return "SqlDbType.DateTime";
        case DbType.DateTime: return "SqlDbType.DateTime";
        case DbType.Decimal: return "SqlDbType.Decimal";
        case DbType.Double: return "SqlDbType.Decimal";
        case DbType.Int16: return "SqlDbType.Int";
        case DbType.Int32: return "SqlDbType.Int";
        case DbType.Int64: return "SqlDbType.Float";
        case DbType.String: return "SqlDbType.VarChar";
        case DbType.StringFixedLength: return "SqlDbType.NChar";
        case DbType.Currency: return "SqlDbType.Decimal";
        default:
        {
         return "__UNKNOWN__" + column.NativeType;
        }
       }
      }
      中查找case DbType.Currency: return "SqlDbType.Decimal";
      若没有,就加上;有则不管。
     ②在public string GetCode(ColumnSchema column)方法中,查找
      case DbType.Decimal:
      case DbType.Currency:
      case DbType.Double:
      {
       sb.Append("            if (dr.Table.Columns.Contains(""+column.Name+"") && !dr.IsNull(""+column.Name+"")) ");
       sb.Append("            { ");
       sb.Append("                model."+GetPropertyNameUpperFirstSub_(column)+" = decimal.Parse(dr[""+column.Name+""].ToString()); ");
       sb.Append("            } ");
       break;
      }
      其中,若没有case DbType.Currency: 那就加上;有则不管。
      谭家泉
      2014年3月24日 15:19:04

  • 相关阅读:
    Java中swing常用控件背景设置透明的方法
    SpringMVC工作原理
    关于spring框架工作原理
    Java-JFrame窗体美化方式
    Java swing GUI窗口美化
    Java-Swing是什么?
    SSM+Redis+Layui前端框架实现验证码的发送
    SSM+Redis+Layui实现注册功能
    SSM+Layui实现模拟登录功能
    SSM+layui分页(了解98%)
  • 原文地址:https://www.cnblogs.com/amintan/p/3620982.html
Copyright © 2020-2023  润新知