Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定类型的数据库架构信息。
        /// </summary>
        /// <typeparam name="T">架构信息的类型。</typeparam>
        /// <param name="database">提供给当前插件的 <see cref="IDatabase"/> 对象。</param>
        /// <param name="predicate">用于测试架构信息是否满足条件的函数。</param>
        /// <returns></returns>
        public virtual IEnumerable <T> GetSchemas <T>(IDatabase database, Expression <Func <T, bool> > predicate = null) where T : ISchemaMetadata
        {
            var restrictionValues = SchemaQueryTranslator.GetRestrictions <T>(predicate, _dicRestrMbrs);

            using var connection = database.CreateConnection();
            try
            {
                switch (GetCategory <T>())
                {
                case SchemaCategory.Database:
                    return((IEnumerable <T>)GetDatabases(database, restrictionValues));

                case SchemaCategory.DataType:
                    return((IEnumerable <T>)GetDataTypes(database, restrictionValues));

                case SchemaCategory.MetadataCollection:
                    return((IEnumerable <T>)GetMetadataCollections(database, restrictionValues));

                case SchemaCategory.ReservedWord:
                    return((IEnumerable <T>)GetReservedWords(database, restrictionValues));

                case SchemaCategory.Table:
                    return((IEnumerable <T>)GetTables(database, restrictionValues));

                case SchemaCategory.Column:
                    return((IEnumerable <T>)GetColumns(database, restrictionValues));

                case SchemaCategory.View:
                    return((IEnumerable <T>)GetViews(database, restrictionValues));

                case SchemaCategory.ViewColumn:
                    return((IEnumerable <T>)GetViewColumns(database, restrictionValues));

                case SchemaCategory.Index:
                    return((IEnumerable <T>)GetIndexs(database, restrictionValues));

                case SchemaCategory.IndexColumn:
                    return((IEnumerable <T>)GetIndexColumns(database, restrictionValues));

                case SchemaCategory.Procedure:
                    return((IEnumerable <T>)GetProcedures(database, restrictionValues));

                case SchemaCategory.ProcedureParameter:
                    return((IEnumerable <T>)GetProcedureParameters(database, restrictionValues));

                case SchemaCategory.ForeignKey:
                    return((IEnumerable <T>)GetForeignKeys(database, restrictionValues));

                case SchemaCategory.User:
                    return((IEnumerable <T>)GetUsers(database, restrictionValues));

                default:
                    return(Enumerable.Empty <T>());
                }
            }
            catch (Exception ex)
            {
                throw new SchemaException(typeof(T).Name, ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取指定类型的数据库架构信息。
        /// </summary>
        /// <typeparam name="T">架构信息的类型。</typeparam>
        /// <param name="database">提供给当前插件的 <see cref="IDatabase"/> 对象。</param>
        /// <param name="predicate">用于测试架构信息是否满足条件的函数。</param>
        /// <returns></returns>
        public virtual IEnumerable <T> GetSchemas <T>(IDatabase database, Expression <Func <T, bool> > predicate = null) where T : ISchemaMetadata
        {
            var indexes           = dicRestrIndex.TryGetValue(typeof(T), () => new Dictionary <string, int>());
            var restrictionValues = SchemaQueryTranslator.GetRestriction(indexes, typeof(T), predicate);
            var category          = GetCategory <T>();

            return(GetSchemas <T>(database, category, restrictionValues));
        }