private TableMapping CreateDefaultTableMapping(ValueTableRow tableRow, Dictionary <string, TableMapping> tableMappingByQueryName) { var queryTableName = tableRow.GetString("ИмяТаблицы"); if (string.IsNullOrEmpty(queryTableName)) { return(null); } var dbTableName = tableRow.GetString("ИмяТаблицыХранения"); if (string.IsNullOrEmpty(dbTableName)) { return(null); } var purpose = tableRow.GetString("Назначение"); ConfigurationItemDescriptor descriptor; object comObject; TableType tableType; if (purpose == "Основная" || purpose == "Константа") { var configurationName = ConfigurationName.ParseOrNull(queryTableName); if (!configurationName.HasValue) { return(null); } tableType = TableType.Main; descriptor = MetadataHelpers.GetDescriptorOrNull(configurationName.Value.Scope); if (descriptor == null) { comObject = null; } else { var configurationItem = globalContext.FindMetaByName(configurationName.Value); comObject = configurationItem.ComObject; } } else if (purpose == "ТабличнаяЧасть") { descriptor = MetadataHelpers.tableSectionDescriptor; var fullname = TableSectionQueryNameToFullName(queryTableName); comObject = ComHelpers.Invoke(globalContext.Metadata, "НайтиПоПолномуИмени", fullname); if (comObject == null) { return(null); } tableType = TableType.TableSection; } else { return(null); } var propertyDescriptors = comObject == null ? new Dictionary <string, string[]>() : MetadataHelpers.GetAttributes(comObject, descriptor) .ToDictionary(Call.Имя, GetConfigurationTypes); var propertyMappings = new ValueTable(tableRow["Поля"]) .Select(x => new { queryName = x.GetString("ИмяПоля"), dbName = x.GetString("ИмяПоляХранения") }) .Where(x => !string.IsNullOrEmpty(x.queryName)) .Where(x => !string.IsNullOrEmpty(x.dbName)) .GroupBy(x => x.queryName, (x, y) => new { queryName = x, columns = y.Select(z => z.dbName).ToArray() }, StringComparer.OrdinalIgnoreCase) .Select(x => { var propertyName = x.queryName.ExcludeSuffix("Кт").ExcludeSuffix("Дт"); var propertyTypes = propertyName == "Счет" ? new[] { "ПланСчетов.Хозрасчетный" } : propertyDescriptors.GetOrDefault(propertyName); if (propertyTypes == null || propertyTypes.Length == 1) { if (x.columns.Length != 1) { return(null); } var nestedTableName = propertyTypes == null ? null : propertyTypes[0]; var singleLayout = new SingleLayout(x.columns[0], nestedTableName); return(new PropertyMapping(x.queryName, singleLayout, null)); } var unionLayout = x.queryName == "Регистратор" ? new UnionLayout( null, GetColumnBySuffixOrNull("_RecorderTRef", x.columns), GetColumnBySuffixOrNull("_RecorderRRef", x.columns), propertyTypes) : new UnionLayout( GetColumnBySuffixOrNull("_type", x.columns), GetColumnBySuffixOrNull("_rtref", x.columns), GetColumnBySuffixOrNull("_rrref", x.columns), propertyTypes); return(new PropertyMapping(x.queryName, null, unionLayout)); }) .NotNull() .ToList(); if (tableType == TableType.TableSection) { if (!HasProperty(propertyMappings, PropertyNames.id)) { var refLayout = new SingleLayout(GetTableSectionIdColumnNameByTableName(dbTableName), null); propertyMappings.Add(new PropertyMapping(PropertyNames.id, refLayout, null)); } if (!HasProperty(propertyMappings, PropertyNames.area)) { var mainQueryName = TableMapping.GetMainQueryNameByTableSectionQueryName(queryTableName); TableMapping mainTableMapping; if (!tableMappingByQueryName.TryGetValue(mainQueryName, out mainTableMapping)) { return(null); } PropertyMapping mainAreaProperty; if (!mainTableMapping.TryGetProperty(PropertyNames.area, out mainAreaProperty)) { return(null); } propertyMappings.Add(mainAreaProperty); } } return(new TableMapping(queryTableName, dbTableName, tableType, propertyMappings.ToArray())); }