Ejemplo n.º 1
0
 // TODO: Вынести метаобъекты в отдельный класс!
 private static DocDef FindMetaobjectDocDef(Guid docId)
 {
     if (_metaobjectDefs == null)
     {
         _metaobjectDefs = new List <DocDef>(MetaobjectDefs.GetMetaobjectDocDefs());
     }
     return(_metaobjectDefs.FirstOrDefault(def => def.Id == docId));
 }
        private static void Prepare(IDataContext dataContext)
        {
            using (var command = dataContext.CreateCommand(GetTableListSql))
            {
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var tableName = reader.GetString(0);
                        var tableType = !reader.IsDBNull(1) ? reader.GetString(1) : String.Empty;

                        Guid tableDocDefId;

                        if (Guid.TryParse(tableName, out tableDocDefId))
                        {
                            AddMap(new DocumentTableMap(tableDocDefId, tableName,
                                                        String.Equals(tableType, "VIEW", StringComparison.OrdinalIgnoreCase)));
                        }
                        else if (tableName.Length == 38) // Временно отключено
                        {
                            var s = tableName.Substring(2).Replace('_', '-');

                            if (Guid.TryParse(s, out tableDocDefId))
                            {
                                AddMap(new DocumentTableMap(tableDocDefId, tableName,
                                                            String.Equals(tableType, "VIEW", StringComparison.OrdinalIgnoreCase)));
                            }
                        }
                    }
                }
            }
            if (Maps.Count > 0)
            {
                PrepareAttributes(dataContext);
            }

            Maps.AddRange(MetaobjectDefs.GetMetaobjectTableMaps()); // Добавляет связи с метаобъектами

            _prepared = true;
        }