public void Condition(Expression <Func <TEntity, bool> > predicate)
        {
            var definitionFactory = new FilterDefinitionFactory <TEntity>();
            var filterDefinition  = definitionFactory.Create(_name, predicate);

            _config.HasTableAnnotation("globalFilter_" + _name, filterDefinition);
        }
        public static EntityTypeConfiguration <TEntity> Filter <TEntity>(this EntityTypeConfiguration <TEntity> config,
                                                                         string filterName, string columnName, object globalValue = null)
            where TEntity : class
        {
            filterName = ScrubFilterName(filterName);
            var filterDefinition = new DynamicFilterDefinition(filterName, null, columnName, typeof(TEntity));

            config.HasTableAnnotation(filterDefinition.AttributeName, filterDefinition);

            if (globalValue != null)
            {
                SetFilterGlobalParameterValue(null, filterName, columnName, globalValue);
            }

            return(config);
        }
Ejemplo n.º 3
0
        /// <summary />
        /// <typeparam name="TEntityType" />
        /// <param name="configuration" />
        /// <param name="columnName" />
        /// <param name="indexName">
        ///     o nome do índice.
        ///     Caso não seja informado, um novo nome será gerado pelo sistema.
        /// </param>
        public static void HasIndexOnDiscriminator <TEntityType>(
            this EntityTypeConfiguration <TEntityType> configuration,
            string columnName = "Discriminator",
            string indexName  = null)
            where TEntityType : class
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            // se o nome do index não foi informado, gera-o.
            if (indexName == null)
            {
                var tableName = typeof(TEntityType).Name;
                indexName = $@"IX_{tableName}_{columnName}";
            }


            configuration.HasTableAnnotation(
                DiscriminatorIndexAnnotation.AnnotationName,
                new DiscriminatorIndexAnnotation(indexName, columnName));
        }