/// <summary> /// 创建SQL实体文件,指定表名 /// </summary> public void CreateClassFilesByTableNames(SqlSugarClient db, string fileDirectory, string nameSpace, params string[] tableNames) { var isLog = db.IsEnableLogEvent; db.IsEnableLogEvent = false; string sql = SqlSugarTool.GetCreateClassSql(null); var tables = db.GetDataTable(sql); if (!FileSugar.IsExistDirectory(fileDirectory)) { FileSugar.CreateDirectory(fileDirectory); } if (tables != null && tables.Rows.Count > 0) { foreach (DataRow dr in tables.Rows) { string tableName = dr["name"].ToString().ToLower(); if (tableNames.Any(it => it.ToLower() == tableName)) { var currentTable = db.GetDataTable(string.Format(SqlSugarTool.GetSelectTopSql(), GetTableNameWithSchema(db, tableName).GetTranslationSqlName())); var tableColumns = GetTableColumns(db, tableName); string className = db.GetClassTypeByTableName(tableName); var classCode = DataTableToClass(currentTable, className, nameSpace, tableColumns); FileSugar.CreateFile(fileDirectory.TrimEnd('\\') + "\\" + className + ".cs", classCode, Encoding.UTF8); } } } db.IsEnableLogEvent = isLog; }
/// <summary> /// 创建SQL实体文件,指定表名 /// </summary> public void CreateClassFilesByTableNames(SqlSugarClient db, string fileDirectory, string nameSpace, params string[] tableNames) { string sql = GetCreateClassSql(null); var tables = db.GetDataTable(sql); if (!FileSugar.IsExistDirectory(fileDirectory)) { FileSugar.CreateDirectory(fileDirectory); } if (tables != null && tables.Rows.Count > 0) { foreach (DataRow dr in tables.Rows) { string tableName = dr["name"].ToString().ToLower(); if (tableNames.Any(it => it.ToLower() == tableName)) { var currentTable = db.GetDataTable(string.Format("select top 1 * from {0}", tableName)); var tableColumns = GetTableColumns(db, tableName); string className = db.GetClassTypeByTableName(tableName); var classCode = DataTableToClass(currentTable, className, nameSpace, tableColumns); FileSugar.CreateFile(fileDirectory.TrimEnd('\\') + "\\" + className + ".cs", classCode, Encoding.UTF8); } } } }