Esempio n. 1
0
        public ConcurrentDictionary <string, ConcurrentDictionary <string, RelationSchema> > GetRelationSchemas()
        {
            var schemaRelations = new ConcurrentDictionary <string, ConcurrentDictionary <string, RelationSchema> >();

            foreach (var entity in RelationEntities)
            {
                if (!schemaRelations.ContainsKey(entity.SchemaName))
                {
                    schemaRelations[entity.SchemaName] = new ConcurrentDictionary <string, RelationSchema>();
                }

                if (!schemaRelations[entity.SchemaName].ContainsKey(entity.RelationName))
                {
                    schemaRelations[entity.SchemaName][entity.RelationName] = new RelationSchema(
                        entity.RelationName,
                        entity.SchemaName,
                        QuotedSchemaRelation(entity.RelationName, entity.SchemaName),
                        ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).ToImmutableArray(),
                        ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).Select(s => s.ColumnName).ToImmutableArray(),
                        ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName && q.IsPrimaryKey).ToImmutableArray(),
                        ColumnEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName && q.IsPrimaryKey).Select(s => s.ColumnName).ToImmutableArray(),
                        UniqueIndexEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).ToImmutableArray(),
                        ForeignKeyEntities.Where(q => q.RelationName == entity.RelationName && q.SchemaName == entity.SchemaName).ToImmutableArray()
                        );
                }
            }

            return(schemaRelations);
        }
Esempio n. 2
0
        public ImmutableArray <UniqueIndexEntity> GetUniqueIndexes(string tableName, string schemaName = DefaultSchema)
        {
            if (!RelationExists(tableName, schemaName))
            {
                throw new DbException($"Relation does not exist: '{tableName}'.'{schemaName}'");
            }

            return(UniqueIndexEntities.Where(q => q.RelationName == tableName && q.SchemaName == schemaName).ToImmutableArray());
        }