private void addReferencesToTemplate(Template template, DAS connection, List <string> loadedReferenceNames = null) { DASDataTable dataTable = null; loadedReferenceNames = loadedReferenceNames ?? new List <string>(); try { addTemplateNameParameter(template.Name, connection); var sqlQuery = string.Format("SELECT ref.{2}, ref.{3} FROM {4} ref WHERE ref.{0} = '{5}' AND ref.{1}={6}", TemplateReferenceTable.Columns.TEMPLATE_TYPE, TemplateReferenceTable.Columns.NAME, TemplateReferenceTable.Columns.REFERENCE_TEMPLATE_TYPE, TemplateReferenceTable.Columns.REFERENCE_NAME, TemplateReferenceTable.NAME, template.TemplateType, _pName); dataTable = connection.ExecuteQueryForDataTable(sqlQuery); } finally { removeNameParameter(connection); } foreach (DASDataRow row in dataTable) { var reference = loadTemplateBy(template.DatabaseType, row.StringAt(TemplateReferenceTable.Columns.REFERENCE_NAME), row.StringAt(TemplateReferenceTable.Columns.REFERENCE_TEMPLATE_TYPE), connection); template.References.Add(reference); if (loadedReferenceNames.Contains(reference.Name)) { continue; } loadedReferenceNames.Add(reference.Name); addReferencesToTemplate(reference, connection, loadedReferenceNames); } }