Beispiel #1
0
        /// <summary>
        /// Gets all entity type foreign keys that are to be used in scaffolding.
        /// </summary>
        /// <param name="entityType">Represents an entity type in an IModel.</param>
        /// <param name="options">Scaffolding options to use in determining entity types.</param>
        /// <returns>Filtered set of foreign keys for scaffolding.</returns>
        public static IEnumerable <IForeignKey> GetScaffoldForeignKeys(this IEntityType entityType, HandlebarsScaffoldingOptions options)
        {
            var foreignKeys = entityType.GetForeignKeys();

            if (options.ExcludedTables != null && options.ExcludedTables.Any())
            {
                var excludedTables = options.ExcludedTables.Select(t => new TableAndSchema(t)).ToList();
                foreignKeys = foreignKeys.Where(f =>
                                                !excludedTables.Any(e =>
                                                                    (string.IsNullOrEmpty(e.Schema) ||
                                                                     string.Equals(f.GetRelatedEntityType(f.DeclaringEntityType).GetSchema(), e.Schema, StringComparison.OrdinalIgnoreCase)) &&
                                                                    string.Equals(f.GetRelatedEntityType(f.DeclaringEntityType).GetTableName(), e.Table, StringComparison.OrdinalIgnoreCase)))
                              .ToList();
            }

            return(foreignKeys);
        }
Beispiel #2
0
        /// <summary>
        /// Gets all entity types that are to be used in scaffolding.
        /// </summary>
        /// <param name="model">Model to retrieve entity types from.</param>
        /// <param name="options">Scaffolding options to use in determining entity types.</param>
        /// <returns>Filtered set of entity types for scaffolding.</returns>
        public static IEnumerable <IEntityType> GetScaffoldEntityTypes(this IModel model, HandlebarsScaffoldingOptions options)
        {
            var entityTypes = model.GetEntityTypes();

            if (options.ExcludedTables != null && options.ExcludedTables.Any())
            {
                // Handle matching view or table name for excludes.
                var excludedTables = options.ExcludedTables.Select(t => new TableAndSchema(t)).ToList();
                entityTypes = (from type in entityTypes
                               let name = type.GetTableName()
                                          let isTable = !string.IsNullOrEmpty(name)
                                                        let table = isTable
                                    ? type.GetTableName()
                                    : type.GetViewName()
                                                                    let schema = isTable
                                    ? type.GetSchema()
                                    : type.GetViewSchema()
                                                                                 where !excludedTables.Any(e =>
                                                                                                           (string.IsNullOrEmpty(e.Schema) ||
                                                                                                            string.Equals(schema, e.Schema, StringComparison.OrdinalIgnoreCase)) &&
                                                                                                           string.Equals(table, e.Table, StringComparison.OrdinalIgnoreCase))
                                                                                 select type).ToList();
            }

            return(entityTypes);
        }
Beispiel #3
0
        /// <summary>
        /// Gets all entity types that are to be used in scaffolding.
        /// </summary>
        /// <param name="model">Model to retrieve entity types from.</param>
        /// <param name="options">Scaffolding options to use in determining entity types.</param>
        /// <returns>Filtered set of entity types for scaffolding.</returns>
        public static IEnumerable <IEntityType> GetScaffoldEntityTypes(this IModel model, HandlebarsScaffoldingOptions options)
        {
            var entityTypes = model.GetEntityTypes();

            if (options.ExcludedTables != null && options.ExcludedTables.Any())
            {
                var excludedTables = options.ExcludedTables.Select(t => new TableAndSchema(t)).ToList();
                entityTypes = entityTypes.Where(t =>
                                                !excludedTables.Any(e =>
                                                                    (string.IsNullOrEmpty(e.Schema) ||
                                                                     string.Equals(t.GetSchema(), e.Schema, StringComparison.OrdinalIgnoreCase)) &&
                                                                    string.Equals(t.GetTableName(), e.Table, StringComparison.OrdinalIgnoreCase)))
                              .ToList();
            }

            return(entityTypes);
        }