zoukankan      html  css  js  c++  java
  • 关键词: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

  • 相关阅读:
    XMAPP搭建DVWA靶机
    博客滑动相册封面导航教程
    MySQL-分页与排序
    MySQL-子查询
    java方法
    JSP小结
    javaScript入门介绍2
    Codeforces Global Round 13
    第一章、OS引论1
    JavaScript入门介绍2021/02/27
  • 原文地址:https://www.cnblogs.com/amintan/p/3620982.html
Copyright © 2011-2022 走看看