/// <summary> /// /// </summary> /// <param name="objectDB"></param> /// <param name="list"></param> /// <param name="dbPath"></param> /// <returns></returns> private string GenerateClass(ObjectDB objectDB, DataTable list, string dbPath = "") { string fileStr = FileManager.ReadFile(FileManager.GetAppPath + "/Template/TemplateClass.cs"); StringBuilder tmpProperties = new StringBuilder(); StringBuilder tmpRelations = new StringBuilder(); StringBuilder tmpConstructRelations = new StringBuilder(); // Properties TableColumns tableColumns = null; foreach (DataRow row in list.Rows) { tmpProperties.Append("\r\n"); tableColumns = new TableColumns(row); tmpProperties.Append(string.Format(@" public {0}{4} {1} {2} get; set; {3}", GetNetType(tableColumns.type), UppercaseFirst(tableColumns.columnName), "{", "}", tableColumns.isNullable ? "?" : "")); } FkTable[] fkList = GetFkRelationShips(objectDB.object_id, TypeSearchRelationship.Direct, dbPath); // Related Properties. foreach (FkTable item in fkList) { tmpRelations.Append("\r\n"); tmpRelations.Append(string.Format(@" public {0} {3} {1} get; set; {2}", item.pkTableName, "{", "}", RemoveLast_S(item.pkTableName))); } // Get Indirect Relationships fkList = GetFkRelationShips(objectDB.object_id, TypeSearchRelationship.Indirect, dbPath); foreach (FkTable item in fkList) { tmpRelations.Append("\r\n"); tmpRelations.Append(string.Format(" public virtual IList<{0}> {0} {1} get; set; {2}\r\n", item.fkTableName, "{", "}")); tmpConstructRelations.Append(string.Format(" {0} = new List<{0}>();\r\n", item.fkTableName, "{", "}")); } // Many to Many - Tables related fkList = GetFkRelationShips(objectDB.object_id, TypeSearchRelationship.ManyToMany, dbPath); foreach (FkTable item in fkList) { tmpRelations.Append(string.Format(" public virtual IList<{0}> {0} {1} get; set; {2}\r\n", item.pkTableName, "{", "}")); tmpConstructRelations.Append(string.Format(" {0} = new List<{0}>();\r\n", item.pkTableName, "{", "}")); } //---------------------------------------------------------------------------------------------- // Relationships fileStr = fileStr.Replace("{0}", txtNamespaceClasses.Text); // Namespace fileStr = fileStr.Replace("{1}", objectDB.name); // Class Name fileStr = fileStr.Replace("{2}", tmpProperties.ToString()); // Properties //GetPrimaryKey("",name) fileStr = fileStr.Replace("{3}", tmpRelations.ToString()); // Declaration Relaciones fileStr = fileStr.Replace("{4}", tmpConstructRelations.ToString()); // Inicializacion de las Relaciones return(fileStr); }
/// <summary> /// Generate Property to .Net Files. /// </summary> /// <param name="tableColumns"></param> /// <returns></returns> private string GenerateMapperProperties(TableColumns tableColumns) { StringBuilder property = new StringBuilder(); property.Append(string.Format(@" Property(x => x.{1}).HasColumnName(""{0}"")", tableColumns.columnName, UppercaseFirst(tableColumns.columnName))); if (!tableColumns.isNullable) { property.Append(".IsRequired()"); } if (GetNetType(tableColumns.type) == "string") { property.Append(".IsUnicode(false)"); } property.Append(";"); property.Append("\r\n"); return(property.ToString()); }