private static void GenerateModel() { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; DataTable tables = Islemler.GetTables(); foreach (DataRow item in tables.Rows) { string Content = string.Empty; string TableName = item["TABLE_NAME"].ToString(); string FolderName = item["FOLDER_NAME"].ToString(); string Columns = string.Empty; DataTable columns = Islemler.GetColumnsNotInPK(TableName); DataTable ForeingKeys = Islemler.GetFK(TableName); DataTable Referances = Islemler.GetRef(TableName); TableName = textInfo.ToTitleCase(textInfo.ToLower(TableName)).Replace("_", ""); foreach (DataRow Col in columns.Rows) { string ColumnName = textInfo.ToTitleCase(textInfo.ToLower(Col["COLUMN_NAME"].ToString())).Replace("_", ""); string DbType = Col["DATA_TYPE"].ToString(); string DataType = string.Empty; switch (DbType) { case "NUMBER": DataType = "decimal"; break; case "CHAR": DataType = "string"; break; case "VARCHAR2": DataType = "string"; break; case "DATE": DataType = "DateTime"; break; case "LONG": DataType = "string"; break; case "LONG RAW": DataType = "string"; break; case "BLOB": DataType = "string"; break; case "CLOB": DataType = "string"; break; default: DataType = "string"; break; } Columns += @" Map(x => x." + ColumnName + @").Column(""" + Col["COLUMN_NAME"].ToString() + @""")" + (Col["NULLABLE"].ToString() == "N" ? ".Not" : string.Empty) + @".Nullable();"; } string FKs = string.Empty; foreach (DataRow fk in ForeingKeys.Rows) { FKs += Environment.NewLine + "\t\t\tReferences(x => x." + textInfo.ToTitleCase(textInfo.ToLower(fk["R_TABLE_NAME"].ToString())).Replace("_", "") + @").Column(""" + fk["COLUMN_NAME"].ToString() + @""");"; } string Refs = string.Empty; foreach (DataRow r in Referances.Rows) { Refs += Environment.NewLine + Environment.NewLine + @"\t\t\tHasMany(x => x." + textInfo.ToTitleCase(textInfo.ToLower(r["TABLE_NAME"].ToString())).Replace("_", "") + @").KeyColumn(""" + r["COLUMN_NAME"].ToString() + @""").Inverse().Cascade.None().ForeignKeyConstraintName(""" + r["CONSTRAINT_NAME"].ToString() + @""");"; } Content = @"using bilisimHR.Common.Helper; using bilisimHR.DataLayer.Core.Entities." + FolderName + @"; namespace " + Namespace + FolderName + @" { public class " + TableName + @"Map: EntityBaseMap<" + TableName + @"> { public " + TableName + @"Map() { Table(""" + item["TABLE_NAME"].ToString() + @"""); LazyLoad(); " + Columns + FKs + Refs + @" } } } "; CreateFiles(TableName + "Map", FolderName, Content); } }
private static void GenerateEntities() { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; DataTable tables = Islemler.GetTables(); foreach (DataRow item in tables.Rows) { string Content = string.Empty; string TableName = item["TABLE_NAME"].ToString(); string FolderName = item["FOLDER_NAME"].ToString(); string Columns = string.Empty; DataTable columns = Islemler.GetColumnsNotInPK(TableName); DataTable ForeingKeys = Islemler.GetFK(TableName); DataTable Referances = Islemler.GetRef(TableName); TableName = textInfo.ToTitleCase(textInfo.ToLower(TableName)).Replace("_", ""); foreach (DataRow Col in columns.Rows) { string ColumnName = textInfo.ToTitleCase(textInfo.ToLower(Col["COLUMN_NAME"].ToString())).Replace("_", ""); string DbType = Col["DATA_TYPE"].ToString(); string DataType = string.Empty; switch (DbType) { case "NUMBER": if (string.IsNullOrEmpty(Col["DATA_SCALE"].ToString()) || Col["DATA_SCALE"].ToString() == "0") { DataType = "int"; } else { DataType = "decimal"; } break; case "CHAR": DataType = "string"; break; case "VARCHAR2": DataType = "string"; break; case "DATE": DataType = "DateTime"; break; case "LONG": DataType = "string"; break; case "LONG RAW": DataType = "string"; break; case "BLOB": DataType = "string"; break; case "CLOB": DataType = "string"; break; default: DataType = "string"; break; } Columns += @" public virtual " + DataType + " " + ColumnName + " { get; set; }"; } string FKs = string.Empty; foreach (DataRow fk in ForeingKeys.Rows) { FKs += Environment.NewLine + Environment.NewLine + "\t\tpublic virtual " + textInfo.ToTitleCase(textInfo.ToLower(fk["R_TABLE_NAME"].ToString())).Replace("_", "") + " " + textInfo.ToTitleCase(textInfo.ToLower(fk["R_TABLE_NAME"].ToString())).Replace("_", "") + " { get; set; }"; } string Refs = string.Empty; foreach (DataRow r in Referances.Rows) { Refs += Environment.NewLine + Environment.NewLine + "\t\tpublic virtual IList<" + textInfo.ToTitleCase(textInfo.ToLower(r["TABLE_NAME"].ToString())).Replace("_", "") + "> " + textInfo.ToTitleCase(textInfo.ToLower(r["TABLE_NAME"].ToString())).Replace("_", "") + " { get; set; }"; } Content = @"using System; using bilisimHR.Common.Core.Entity; using System.Collections.Generic; namespace " + Namespace + FolderName + @" { public class " + TableName + @" : Entity<int> {" + Columns + FKs + Refs + @" } } "; CreateFiles(TableName, FolderName, Content); } }
private static void GenerateModel() { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; DataTable tables = Islemler.GetTables(); foreach (DataRow item in tables.Rows) { string Content = string.Empty; string TableName = item["TABLE_NAME"].ToString(); string FolderName = item["FOLDER_NAME"].ToString(); string Columns = string.Empty; DataTable columns = Islemler.GetColumns(TableName); DataTable ForeingKeys = Islemler.GetFK(TableName); DataTable Referances = Islemler.GetRef(TableName); TableName = textInfo.ToTitleCase(textInfo.ToLower(TableName)).Replace("_", ""); foreach (DataRow Col in columns.Rows) { string ColumnName = textInfo.ToTitleCase(textInfo.ToLower(Col["COLUMN_NAME"].ToString())).Replace("_", ""); string DbType = Col["DATA_TYPE"].ToString(); string DataType = string.Empty; switch (DbType) { case "NUMBER": DataType = "decimal"; break; case "CHAR": DataType = "string"; break; case "VARCHAR2": DataType = "string"; break; case "DATE": DataType = "DateTime"; break; case "LONG": DataType = "string"; break; case "LONG RAW": DataType = "string"; break; case "BLOB": DataType = "string"; break; case "CLOB": DataType = "string"; break; default: DataType = "string"; break; } Columns += @" " + (Col["NULLABLE"].ToString() == "N" ? Environment.NewLine + "\t\t[Required]" : string.Empty) + @" public " + DataType + " " + ColumnName + " { get; set; }"; } string FKs = string.Empty; foreach (DataRow fk in ForeingKeys.Rows) { FKs += Environment.NewLine + Environment.NewLine + "\t\tpublic " + textInfo.ToTitleCase(textInfo.ToLower(fk["R_TABLE_NAME"].ToString())).Replace("_", "") + "Model " + textInfo.ToTitleCase(textInfo.ToLower(fk["R_TABLE_NAME"].ToString())).Replace("_", "") + " { get; }"; } string Refs = string.Empty; foreach (DataRow r in Referances.Rows) { Refs += Environment.NewLine + Environment.NewLine + "\t\tpublic virtual IList<" + textInfo.ToTitleCase(textInfo.ToLower(r["TABLE_NAME"].ToString())).Replace("_", "") + "Model> " + textInfo.ToTitleCase(textInfo.ToLower(r["TABLE_NAME"].ToString())).Replace("_", "") + " { get; set; }"; } Content = @"using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace " + Namespace + FolderName + @" { public class " + TableName + @"Model : BaseModel<uint> {" + Columns + FKs + Refs + @" } } "; CreateFiles(TableName + "Model", FolderName, Content); } }