Example #1
0
        /// <summary>
        /// Further configuration the model
        /// </summary>
        /// <param name="modelBuilder">The builder being used to construct the model for this context</param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            IEnumerable <Type> typeConfigurations = Assembly.GetExecutingAssembly().GetTypes().Where(type =>
                                                                                                     (type.BaseType?.IsGenericType ?? false) &&
                                                                                                     (type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration <>) ||
                                                                                                      type.BaseType.GetGenericTypeDefinition() == typeof(QueryTypeConfiguration <>)));

            foreach (Type typeConfiguration in typeConfigurations)
            {
                IMappingConfiguration configuration = (IMappingConfiguration)Activator.CreateInstance(typeConfiguration);
                configuration.ApplyConfiguration(modelBuilder);
            }
            base.OnModelCreating(modelBuilder);
        }
        /// <summary>
        ///     Further configuration the model
        /// </summary>
        /// <param name="modelBuilder">The builder being used to construct the model for this context</param>
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Dynamically load all entity and query type configurations
            IEnumerable <Type> typeConfigurations = AppDomain.CurrentDomain.GetAssemblies().SelectMany(assembly => assembly.GetTypes().Where(type =>
                                                                                                                                             (type.BaseType?.IsGenericType ?? false) &&
                                                                                                                                             type.BaseType.GetGenericTypeDefinition() == typeof(CustomEntityTypeConfiguration <>)));

            foreach (Type typeConfiguration in typeConfigurations)
            {
                IMappingConfiguration configuration = (IMappingConfiguration)Activator.CreateInstance(typeConfiguration);
                configuration?.ApplyConfiguration(modelBuilder);
            }

            base.OnModelCreating(modelBuilder);
        }