zoukankan      html  css  js  c++  java
  • 三层自动生成



    二章    代码生成器



    16节
    动软代码生成器使用

    //服务器--添加服务器--测试连接--选择表--单表代码生成器--生成ModelDALBLL
    //服务器--添加服务器--测试连接--选择表--代码批量生成--
    //服务器--添加服务器--测试连接--选择表--数据库下新建项目--工厂模式结构--



    17-19节
    自己动手手写代码生成器

    //1    加载所有数据表
    select *,TABLE_NAME from INFORMATION_SCHEMA.TABLES; //获得当前DBS下的所有表架构
    this.listTable.Items.Add(reader[0].ToString()); //把数据表加入列表
    //2    生成Model (多行MultiLine,滚轴ScrollBars)
    string tablename =  this.listTable.SelectedItem.TOString();
    //namespacename
    //StringBulider
    //sb.AppendLine("");//拼接

    select *,COLUMN_NAME,IS_NULLABLE,DATA_TYPE from INFORMATION_SCHEMA.COLUMNS where table_name='T_UserInfo'; //获得信息架构中的所有列名  ////只查询了userinfo表,没有查询customerinfo表---------------???--------------------------

    //3    写一个方法完成C#与DBS中类型的对象关系
    private string DbTypeToCSharpType(string dbtype)
    {
        string ctype=string.Empty; //默认空字符串
        switch(dbtype)
        {
            case "int":ctype="int";break;
            case "char":
            case "nchar":
            case "varchar":
            case "nvarchar":ctype="string";break;
            case "bit":ctype="boolean";break;
            case "datetime":ctype="DateTime";break;
            default :throw new Exception("该数据库类型不存在,需要新增对应类型");
        }
        return ctype;
    }

    //判断该列是否可null并获得最终类型
    private static string CheckIsNullableGetLastType(string isNullable,string cType)
    {
        if (cType != "string")
        {
            return isNullable == "YES" ? cType + "?" : cType;
        }
        else
        {
            return cType;
        }
    }




  • 相关阅读:
    RHCE考试(Linux7)
    RHCSA考试(Linux7)
    调整Linux最大文件打开数
    记一次渗透测试面试题
    反序列化漏洞
    cisp-pte靶场通关思路分享----xss篇
    cisp-pte靶场通关思路分享----远程文件包含篇
    利用python轻松搭建http服务器
    cisp-pte靶场通关思路分享----综合题篇
    cisp-pte靶场通关思路分享----日志分析篇
  • 原文地址:https://www.cnblogs.com/adolphyang/p/4750205.html
Copyright © 2011-2022 走看看