Exemplo n.º 1
0
        /// <summary>
        /// 获取勾选的表信息
        /// </summary>
        /// <returns></returns>
        private List <ModelTable> getCheckedTableName()
        {
            List <ModelTable> list = new List <ModelTable>();
            ModelTable        model;

            for (int i = 0; i < this.dgvTables.Rows.Count; i++)
            {
                if (this.dgvTables.Rows[i].Cells["ckbCheck"].Value != null && (bool)this.dgvTables.Rows[i].Cells["ckbCheck"].Value)
                {
                    model              = new ModelTable();
                    model.Table_Name   = this.dgvTables.Rows[i].Cells["table_name"].Value.ToString();
                    model.TabCamelName = this.dgvTables.Rows[i].Cells["table_camel_name"].Value.ToString();
                    model.PrimayKey    = this.dgvTables.Rows[i].Cells["primay_key"].Value.ToString();

                    if (this.dgvTables.Rows[i].Cells["comments"].Value != null)
                    {
                        model.Comments = this.dgvTables.Rows[i].Cells["comments"].Value.ToString();
                    }
                    else
                    {
                        model.Comments = "";
                    }
                    list.Add(model);
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 生成DAL
        /// </summary>
        /// <param name="dbTableName">数据库中的表名称</param>
        /// <param name="tableCamelName">参与生成的表名称(可能是数据表名称也可能是表名称的骆驼表示法</param>
        public void GenerateEs(Enumeration.DataBaseType DBType, ModelTable mt)
        {
            StringBuilder sbTemp    = new StringBuilder();
            DataTable     dtColumns = SelectColumnsByTableName(DBType, mt.Table_Name);

            string colName = string.Empty;

            #region 内容

            sbTemp.Append("using DBModels;\r\n");
            sbTemp.Append("using System;\r\n");
            sbTemp.Append("using System.Collections.Generic;\r\n");
            sbTemp.Append("using System.Linq;\r\n");
            sbTemp.Append("using System.Text;\r\n");
            sbTemp.Append("using System.Threading.Tasks;\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("namespace EsDal\r\n");
            sbTemp.Append("{\r\n");
            sbTemp.Append("    public class " + mt.TabCamelName + "ES : Base.EsBase\r\n");
            sbTemp.Append("    {\r\n");
            sbTemp.Append("        /// <summary>\r\n");
            sbTemp.Append("        /// 根据关键字和数据更新时间删除数据\r\n");
            sbTemp.Append("        /// </summary>\r\n");
            sbTemp.Append("        /// <param name=\"keyword\">关键字</param>\r\n");
            sbTemp.Append("        /// <returns></returns>\r\n");
            sbTemp.Append("        public bool DeleteByKeyword(string keyword)\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            var queryString = \"iD: (\\\"\" + keyword + \"\\\")\";\r\n");
            sbTemp.Append("            var response = client.DeleteByQuery<" + mt.TabCamelName + ">(p => p.Query(q => q.QueryString(o => o.Query(queryString))));\r\n");
            sbTemp.Append("            return response.Total > 0;\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("    }\r\n");
            sbTemp.Append("}\r\n");

            #endregion

            // 生成cs文件
            generateFile("ES", Words.ToSingular(mt.TabCamelName + "ES"), sbTemp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取勾选的表信息
        /// </summary>
        /// <returns></returns>
        private List<ModelTable> getCheckedTableName()
        {
            List<ModelTable> list = new List<ModelTable>();
            ModelTable model;
            for (int i = 0; i < this.dgvTables.Rows.Count; i++)
            {
                if (this.dgvTables.Rows[i].Cells["ckbCheck"].Value != null && (bool)this.dgvTables.Rows[i].Cells["ckbCheck"].Value)
                {
                    model = new ModelTable();
                    model.Table_Name = this.dgvTables.Rows[i].Cells["table_name"].Value.ToString();
                    model.TabCamelName = this.dgvTables.Rows[i].Cells["table_camel_name"].Value.ToString();
                    model.PrimayKey = this.dgvTables.Rows[i].Cells["primay_key"].Value.ToString();

                    if (this.dgvTables.Rows[i].Cells["comments"].Value != null)
                    {
                        model.Comments = this.dgvTables.Rows[i].Cells["comments"].Value.ToString();
                    }
                    else
                    {
                        model.Comments = "";
                    }
                    list.Add(model);
                }
            }
            return list;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 生成实体类
        /// </summary>
        /// <param name="dbTableName">数据库中的表名称</param>
        /// <param name="tableCamelName">参与生成的表名称(可能是数据表名称也可能是表名称的骆驼表示法</param>
        public void GenerateModel(Enumeration.DataBaseType DBType, ModelTable mt)
        {
            StringBuilder sbTemp    = new StringBuilder();
            DataTable     dtColumns = SelectColumnsByTableName(DBType, mt.Table_Name);

            string colName = string.Empty;

            #region 生成命名空间和类
            sbTemp.Append("using System;"); //引入命名空间
            sbTemp.Append("\r\nusing Nest;");
            sbTemp.Append("\r\nusing System.ComponentModel;");
            sbTemp.Append("\r\nusing System.Collections.Generic;");
            sbTemp.Append("\r\nusing System.ComponentModel.DataAnnotations;");
            sbTemp.Append("\r\nusing System.ComponentModel.DataAnnotations.Schema;");
            sbTemp.Append("\r\n");
            sbTemp.Append("\r\n").Append("namespace ").Append(NameSpaceModel);    //命名空间
            sbTemp.Append("\r\n").Append("{");
            sbTemp.Append("\r\n").Append("\t/// <summary>");
            sbTemp.Append("\r\n").Append("\t///").Append(GetTableComments(DBType, mt.Table_Name)
                                                         .Replace("\r\n", " ")
                                                         .Replace("\n", " "));
            sbTemp.Append("\r\n").Append("\t/// </summary>");
            sbTemp.Append("\r\n").Append("\t[Serializable]");
            sbTemp.Append("\r\n").Append("\t[Table(\"" + mt.Table_Name + "\")]");
            sbTemp.Append("\r\n").Append("\t[ElasticsearchType(Name = \"" + mt.Table_Name + "\")]");
            sbTemp.Append("\r\n").Append("\tpublic partial class ")
            .Append(Words.ToSingular(Words.reWriteWord(mt.TabCamelName)));
            sbTemp.Append("\r\n").Append("\t{");    //类
            #endregion

            #region 生成属性
            for (int i = 0; i < dtColumns.Rows.Count; i++)
            {
                //string tempTableName = dtColumns.Rows[i]["TABLE_NAME"].ToString();
                string tempColumnName = dtColumns.Rows[i]["COLUMN_NAME"].ToString();
                tempColumnName = tempColumnName == mt.Table_Name ? tempColumnName + "1" : tempColumnName;//如果字段名和表明相同,就在字段名后面加上字符"1"
                colName        = tempColumnName;

                string tempType        = dtColumns.Rows[i]["DATA_TYPE"].ToString();
                string tempLength      = dtColumns.Rows[i]["DATA_LENGTH"].ToString();
                string tempPrecision   = dtColumns.Rows[i]["DATA_PRECISION"].ToString();
                string tempScale       = dtColumns.Rows[i]["DATA_SCALE"].ToString();
                string tempNullAble    = dtColumns.Rows[i]["NULLABLE"].ToString();
                string tempDescription = dtColumns.Rows[i]["COMMENTS"].ToString().Replace("\r\n", " ").Replace("\n", " ");

                //if (string.IsNullOrWhiteSpace(tempScale))
                //{
                //    tempScale = "0";
                //}

                //属性
                sbTemp.Append("\r\n");
                sbTemp.Append("\r\n\t\t/// <summary>");
                sbTemp.Append("\r\n\t\t///").Append(tempDescription);
                sbTemp.Append("\r\n\t\t/// </summary>");
                //[Nest.String(Index = FieldIndexOption.NotAnalyzed)]
                //[Nest.String(Analyzer = "standard")]

                sbTemp.Append("\r\n\t\t[Display(Name = \"").Append(PublicHelper.GetCamelName(colName)).Append("\")]");
                if (tempNullAble == "N" || tempNullAble == "NO")
                {
                    sbTemp.Append("\r\n\t\t[Required]");
                }
                string ColType = DataTypeConvert.ConvertTypeVS2008(dtColumns.Rows[i]);
                if (ColType == "string")
                {
                    if (tempLength == "")
                    {
                        if (tempType == "text" || tempType == "character varying")
                        {
                            sbTemp.Append("\r\n\t\t[StringLength(").Append("8000").Append(")]");
                        }
                        else
                        {
                            MessageBox.Show("提示!", "未知类型:" + tempType, MessageBoxButtons.OK,
                                            MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                        }
                    }
                    else
                    {
                        sbTemp.Append("\r\n\t\t[StringLength(").Append(tempLength).Append(")]");
                    }
                }
                //sbTemp.Append("\r\n\t\t[Column(TypeName = \"").Append(ColType).Append("\")]");

                //是否主键
                if (mt.PrimayKey.Equals(colName))
                {
                    sbTemp.Append("\r\n\t\t[Key]");
                    sbTemp.Append("\r\n\t\t[Keyword]");
                }

                sbTemp.Append("\r\n\t\tpublic ")
                .Append(ColType)
                .Append(" ")
                .Append(Words.reWriteWord(colName))
                .Append(" { get; set; }");
            }
            sbTemp.Append("\r\n\t}");
            sbTemp.Append("\r\n}");
            #endregion

            // 生成cs文件
            generateFile("Models", Words.ToSingular(mt.TabCamelName), sbTemp);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 生成DAL
        /// </summary>
        /// <param name="dbTableName">数据库中的表名称</param>
        /// <param name="tableCamelName">参与生成的表名称(可能是数据表名称也可能是表名称的骆驼表示法</param>
        public void GenerateDal(Enumeration.DataBaseType DBType, ModelTable mt)
        {
            StringBuilder sbTemp    = new StringBuilder();
            DataTable     dtColumns = SelectColumnsByTableName(DBType, mt.Table_Name);

            string colName = string.Empty;

            #region 内容
            sbTemp.Append("using DBModels;\r\n");
            sbTemp.Append("using Models;\r\n");
            sbTemp.Append("using System.Collections.Generic;\r\n");
            sbTemp.Append("using System.Linq;\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("namespace DAL\r\n");
            sbTemp.Append("{\r\n");
            sbTemp.Append("    public class " + mt.TabCamelName + "DAL : Base<" + mt.TabCamelName + ">\r\n");
            sbTemp.Append("    {\r\n");
            sbTemp.Append("        /// <summary>\r\n");
            sbTemp.Append("        /// 获取分页列表(模糊搜索)\r\n");
            sbTemp.Append("        /// </summary>\r\n");
            sbTemp.Append("        /// <param name=\"PageIndex\">页码</param>\r\n");
            sbTemp.Append("        /// <param name=\"PageSize\">页容量</param>\r\n");
            sbTemp.Append("        /// <returns></returns>\r\n");
            sbTemp.Append("        public PageModel<" + mt.TabCamelName + "> GetList(int PageIndex, int PageSize, string search)\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            using (dbContext db = new dbContext())\r\n");
            sbTemp.Append("            {\r\n");
            sbTemp.Append("                PageModel<" + mt.TabCamelName + "> model = new PageModel<" + mt.TabCamelName + ">();\r\n");
            sbTemp.Append("                var linq = db." + mt.TabCamelName + "s;\r\n");
            sbTemp.Append("                //if (CommHelper.CurrentUser != null && !CommHelper.CurrentUser.LoginName.ToLower().Contains(\"admin\"))\r\n");
            sbTemp.Append("                //{\r\n");
            sbTemp.Append("                //    linq = linq.Where(o => o.Creator == CommHelper.CurrentUser.ID);\r\n");
            sbTemp.Append("                //}\r\n");
            sbTemp.Append("                //if (!string.IsNullOrEmpty(search))\r\n");
            sbTemp.Append("                //{\r\n");
            sbTemp.Append("                //    linq = linq.Where(t => t.Keyword != null && t.Keyword.Contains(search));\r\n");
            sbTemp.Append("                //}\r\n");
            sbTemp.Append("                model.Total = linq.Count();\r\n");
            sbTemp.Append("                model.Data = linq.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();\r\n");
            sbTemp.Append("                return model;\r\n");
            sbTemp.Append("            }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        /// <summary>\r\n");
            sbTemp.Append("        /// 获取分页列表(模糊搜索) 查询状态 0未开始,1成功,2失败\r\n");
            sbTemp.Append("        /// </summary>\r\n");
            sbTemp.Append("        /// <param name=\"PageIndex\"></param>\r\n");
            sbTemp.Append("        /// <param name=\"PageSize\"></param>\r\n");
            sbTemp.Append("        /// <param name=\"search\">关键字</param>\r\n");
            sbTemp.Append("        /// <param name=\"state\">状态(0未开始,1成功,2失败)</param>\r\n");
            sbTemp.Append("        /// <returns></returns>\r\n");
            sbTemp.Append("        public PageModel<" + mt.TabCamelName + "> GetList(int PageIndex, int PageSize, string search,int state)\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            using (dbContext db = new dbContext())\r\n");
            sbTemp.Append("            {\r\n");
            sbTemp.Append("                PageModel<" + mt.TabCamelName + "> model = new PageModel<" + mt.TabCamelName + ">();\r\n");
            sbTemp.Append("                IQueryable<" + mt.TabCamelName + "> linq= null;\r\n");
            sbTemp.Append("                if (state==0)\r\n");
            sbTemp.Append("                {\r\n");
            sbTemp.Append("                    //只查询未开始的\r\n");
            sbTemp.Append("                     linq = db." + mt.TabCamelName + "s;\r\n");
            sbTemp.Append("                }\r\n");
            sbTemp.Append("                else\r\n");
            sbTemp.Append("                {\r\n");
            sbTemp.Append("                    linq = db." + mt.TabCamelName + "s;\r\n");
            sbTemp.Append("                }\r\n");
            sbTemp.Append("                //if (!string.IsNullOrEmpty(search))\r\n");
            sbTemp.Append("                //{\r\n");
            sbTemp.Append("                //    linq = linq.Where(t => t.Keyword != null && t.Keyword.Contains(search));\r\n");
            sbTemp.Append("                //}\r\n");
            sbTemp.Append("                model.Total = linq.Count();\r\n");
            sbTemp.Append("                //model.Data = linq.OrderByDescending(t => t.ModifyTime).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();\r\n");
            sbTemp.Append("                model.Data = linq.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();\r\n");
            sbTemp.Append("                return model;\r\n");
            sbTemp.Append("            }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        /// <summary>\r\n");
            sbTemp.Append("        /// 判断是否存在\r\n");
            sbTemp.Append("        /// </summary>\r\n");
            sbTemp.Append("        /// <param name=\"ClientID\">用户ID</param>\r\n");
            sbTemp.Append("        /// <param name=\"Keyword\">产品参数</param>\r\n");
            sbTemp.Append("        /// <param name=\"Name\">微博名称</param>\r\n");
            sbTemp.Append("        /// <param name=\"Enterprise\">企业名</param>\r\n");
            sbTemp.Append("        /// <returns></returns>\r\n");
            sbTemp.Append("        public bool IsExist(string ClientID, string Keyword, string Name, string Enterprise)\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            bool result = false;\r\n");
            sbTemp.Append("            using (dbContext db = new dbContext())\r\n");
            sbTemp.Append("            {\r\n");
            sbTemp.Append("                //var model = db." + mt.TabCamelName + "s.Where(t => t.DeleteTime == null && t.ClientID == ClientID && t.Keyword == Keyword && t.Name == Name && t.EnterpriseName == Enterprise).FirstOrDefault();\r\n");
            sbTemp.Append("                var model = db." + mt.TabCamelName + "s.FirstOrDefault();\r\n");
            sbTemp.Append("                if (model != null)\r\n");
            sbTemp.Append("                {\r\n");
            sbTemp.Append("                    result = true;\r\n");
            sbTemp.Append("                }\r\n");
            sbTemp.Append("                return result;\r\n");
            sbTemp.Append("            }\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        /// <summary>\r\n");
            sbTemp.Append("        /// 获取全量分页列表(模糊搜索)\r\n");
            sbTemp.Append("        /// </summary>\r\n");
            sbTemp.Append("        /// <param name=\"PageIndex\"></param>\r\n");
            sbTemp.Append("        /// <param name=\"PageSize\"></param>\r\n");
            sbTemp.Append("        /// <returns></returns>\r\n");
            sbTemp.Append("        public PageModel<" + mt.TabCamelName + "> GetFullList(int PageIndex, int PageSize, string search, int fullstate = 0)\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            using (dbContext db = new dbContext())\r\n");
            sbTemp.Append("            {\r\n");
            sbTemp.Append("                PageModel<" + mt.TabCamelName + "> model = new PageModel<" + mt.TabCamelName + ">();\r\n");
            sbTemp.Append("                // t.IsFull = 2为开启全量抓取\r\n");
            sbTemp.Append("                var linq = db." + mt.TabCamelName + "s;\r\n");
            sbTemp.Append("                //if (!string.IsNullOrEmpty(search))\r\n");
            sbTemp.Append("                //{\r\n");
            sbTemp.Append("                //    linq = linq.Where(t => t.Keyword != null && t.Keyword.Contains(search));\r\n");
            sbTemp.Append("                //}\r\n");
            sbTemp.Append("                model.Total = linq.Count();\r\n");
            sbTemp.Append("                //model.Data = linq.OrderByDescending(t => t.ModifyTime).Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();\r\n");
            sbTemp.Append("                model.Data = linq.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();\r\n");
            sbTemp.Append("                return model;\r\n");
            sbTemp.Append("            }\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        /// <summary>\r\n");
            sbTemp.Append("        /// 获取分页列表(模糊搜索)\r\n");
            sbTemp.Append("        /// </summary>\r\n");
            sbTemp.Append("        /// <param name=\"PageIndex\"></param>\r\n");
            sbTemp.Append("        /// <param name=\"PageSize\"></param>\r\n");
            sbTemp.Append("        /// <param name=\"ClientID\">用户ID</param>\r\n");
            sbTemp.Append("        /// <returns></returns>\r\n");
            sbTemp.Append("        public PageModel<" + mt.TabCamelName + "> GetList(int PageIndex, int PageSize, string ClientID, string search)\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            using (dbContext db = new dbContext())\r\n");
            sbTemp.Append("            {\r\n");
            sbTemp.Append("                PageModel<" + mt.TabCamelName + "> model = new PageModel<" + mt.TabCamelName + ">();\r\n");
            sbTemp.Append("                var linq = db." + mt.TabCamelName + "s;\r\n");
            sbTemp.Append("                //if (!string.IsNullOrEmpty(search))\r\n");
            sbTemp.Append("                //{\r\n");
            sbTemp.Append("                //    linq = linq.Where(t => t.Keyword != null && t.Keyword.Contains(search));\r\n");
            sbTemp.Append("                //}\r\n");
            sbTemp.Append("                model.Total = linq.Count();\r\n");
            sbTemp.Append("                model.Data = linq.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();\r\n");
            sbTemp.Append("                return model;\r\n");
            sbTemp.Append("            }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        public int GetTotalCount()\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            using (dbContext db = new dbContext())\r\n");
            sbTemp.Append("            {\r\n");
            sbTemp.Append("                return db." + mt.TabCamelName + "s.Count();\r\n");
            sbTemp.Append("            }\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("        /// <summary>\r\n");
            sbTemp.Append("        /// 分页获取list数据\r\n");
            sbTemp.Append("        /// </summary>\r\n");
            sbTemp.Append("        /// <param name=\"pageIndex\"></param>\r\n");
            sbTemp.Append("        /// <param name=\"pageSize\"></param>\r\n");
            sbTemp.Append("        /// <returns></returns>\r\n");
            sbTemp.Append("        public List<" + mt.TabCamelName + "> GetListByPage(int pageIndex, int pageSize)\r\n");
            sbTemp.Append("        {\r\n");
            sbTemp.Append("            using (dbContext db = new dbContext())\r\n");
            sbTemp.Append("            {\r\n");
            sbTemp.Append("                //return db." + mt.TabCamelName + "s.OrderBy(o => o.ID).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();\r\n");
            sbTemp.Append("                return db." + mt.TabCamelName + "s.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();\r\n");
            sbTemp.Append("            }\r\n");
            sbTemp.Append("        }\r\n");
            sbTemp.Append("    }\r\n");
            sbTemp.Append("}\r\n");

            #endregion

            // 生成cs文件
            generateFile("DAL", Words.ToSingular(mt.TabCamelName + "DAL"), sbTemp);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 生成Mapping
        /// </summary>
        /// <param name="dbTableName">数据库中的表名称</param>
        public void GenerateMapping(Enumeration.DataBaseType DBType, ModelTable mt)
        {
            String        dbTableName = mt.Table_Name;
            StringBuilder sbTemp      = new StringBuilder();
            DataTable     dtColumns   = SelectColumnsByTableName(DBType, dbTableName);

            string colName = string.Empty;

            #region 生成命名空间和类
            sbTemp.Append("using System.ComponentModel.DataAnnotations.Schema;");
            sbTemp.Append("\r\n");
            sbTemp.Append("using System.Data.Entity.ModelConfiguration;");
            sbTemp.Append("\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("namespace ").Append(NameSapceMaping);    //命名空间
            sbTemp.Append("\r\n");
            sbTemp.Append("{");
            sbTemp.Append("\r\n");
            sbTemp.Append("\tpublic class ").Append(Words.ToSingular(dbTableName))
            .Append("Map : EntityTypeConfiguration<").Append(Words.ToSingular(dbTableName)).Append(">");;
            sbTemp.Append("\r\n");
            sbTemp.Append("\t{");    //类
            #endregion

            #region 生成构造函数
            sbTemp.Append("\r\n");
            //sbTemp.Append("\t\t/// <summary>");
            //sbTemp.Append("\r\n");
            //sbTemp.Append("\t\t///").Append("构造函数");
            //sbTemp.Append("\r\n");
            //sbTemp.Append("\t\t/// </summary>");
            //sbTemp.Append("\r\n");
            sbTemp.Append("\t\tpublic ").Append(Words.ToSingular(dbTableName)).Append("Map").Append("()");
            sbTemp.Append("\r\n");
            sbTemp.Append("\t\t{");
            sbTemp.Append("\r\n");
            sbTemp.Append("\r\n");

            #region 主键
            sbTemp.Append("\t\t\t// Primary Key");
            sbTemp.Append("\r\n");
            List <string> keyList = GetPrimayKeys(DBType, dbTableName);

            List <string> keyList2 = keyList;


            if (keyList.Count == 0)
            {
                keyList = GetNotNullColumns(DBType, dbTableName);
                sbTemp.Append("\t\t\t//缺少主键!");
                //MessageBox.Show(tableName + "缺少主键!");
                //return;
            }
            else if (keyList.Count == 1)
            {
                sbTemp.Append("\t\t\tthis.HasKey(t => t.").Append(keyList[0]).Append(");");
            }
            else
            {
                sbTemp.Append("\t\t\tthis.HasKey(t => new {")
                .Append("t.").Append(string.Join(",t.", keyList.ToArray())).Append("});");
            }
            #endregion

            sbTemp.Append("\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("\t\t\t// Properties");
            for (int i = 0; i < dtColumns.Rows.Count; i++)
            {
                string tempColumnName = dtColumns.Rows[i]["COLUMN_NAME"].ToString();
                tempColumnName = tempColumnName == dbTableName ? tempColumnName + "1" : tempColumnName;//如果字段名和表明相同,就在字段名后面加上字符"1"
                colName        = tempColumnName;
                string tempType    = dtColumns.Rows[i]["DATA_TYPE"].ToString().ToUpper();
                string strNullAble = dtColumns.Rows[i]["NULLABLE"].ToString();
                string sLength     = dtColumns.Rows[i]["DATA_LENGTH"].ToString();
                int    maxLength   = int.Parse(sLength == "" ? "0" : sLength);

                StringBuilder sb = new StringBuilder();

                if (keyList2.Contains(colName))
                {
                    //产生问题:The changes to the database were committed successfully, but an error occurred while updating the object context
                    //sb.Append("\r\n");
                    //sb.Append("\t\t\t.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None)");
                }

                if (strNullAble == "N" || strNullAble == "NO")
                {
                    sb.Append("\r\n");
                    sb.Append("\t\t\t.IsRequired()");
                }

                if (tempType == "MEDIUMTEXT" || tempType == "TEXT" || tempType == "VARCHAR" || //MySQL
                    tempType == "CHAR" || tempType == "CLOB" || tempType == "LONG" ||       //Oracle
                    tempType == "NCHAR" || tempType == "NCLOB" || tempType == "NVARCHAR2" ||
                    tempType == "ROWID" || tempType == "VARCHAR2")
                {
                    if (tempType == "CHAR" || tempType == "NCHAR")
                    {
                        sb.Append("\r\n");
                        sb.Append("\t\t\t.IsFixedLength()");
                    }

                    if (maxLength > 0)
                    {
                        sb.Append("\r\n");
                        sb.Append("\t\t\t.HasMaxLength(").Append(maxLength).Append(")");
                    }
                }

                if (sb.Length > 0)
                {
                    sbTemp.Append("\r\n");
                    sbTemp.Append("\t\t\tthis.Property(t => t.").Append(Words.reWriteWord(colName)).Append(")");
                    sbTemp.Append(sb);
                    sbTemp.Append(";");
                    sbTemp.Append("\r\n");
                }
            }
            sbTemp.Append("\r\n");
            sbTemp.Append("\r\n");
            sbTemp.Append("\t\t\t// Table & Column Mappings");
            sbTemp.Append("\r\n");
            sbTemp.Append("\t\t\tthis.ToTable(\"")
            .Append(Words.reWriteWord(dbTableName)).Append("\", \"" + dbSchema + "\");");

            for (int i = 0; i < dtColumns.Rows.Count; i++)
            {
                string tempColumnName = dtColumns.Rows[i]["COLUMN_NAME"].ToString();
                colName        = tempColumnName;
                tempColumnName = tempColumnName == dbTableName ? tempColumnName + "1" : tempColumnName;//如果字段名和表明相同,就在字段名后面加上字符"1"
                sbTemp.Append("\r\n");
                sbTemp.Append("\t\t\tthis.Property(t => t.")
                .Append(Words.reWriteWord(tempColumnName))
                .Append(").HasColumnName(\"")
                .Append(colName)
                .Append("\");");
            }
            sbTemp.Append("\r\n\t\t}");
            sbTemp.Append("\r\n\t}");
            sbTemp.Append("\r\n}");

            #endregion

            // 生成cs文件
            generateFile("Models\\Mapping", Words.ToSingular(dbTableName) + "Map", sbTemp);
        }