/// <summary>
        /// Gets the available seeds.
        /// </summary>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public IEnumerable <SeedInfo> GetAvailableSeeds(string dbContextType)
        {
            var availableSeeds = new Dictionary <Type, SeedInfo>();

            CheckSeedClassesIntegrity();

            foreach (var type in Assembly.DefinedTypes)
            {
                var seederAttribute = type.GetCustomAttribute <SeedAttribute>(true);

                if (seederAttribute == null)
                {
                    continue;
                }

                var dbContextAttribute = type.GetCustomAttribute <DbContextAttribute>(true);

                if (dbContextAttribute != null && dbContextAttribute.ContextType.Name != dbContextType)
                {
                    continue;
                }

                var seederAttributeInfo = new SeedInfo(type, seederAttribute);

                yield return(seederAttributeInfo);
            }
        }
        /// <summary>
        /// Runs the seed.
        /// </summary>
        /// <param name="availableSeed">The available seed.</param>
        protected override void RunSeed(SeedInfo availableSeed)
        {
            base.RunSeed(availableSeed);

            var insertScript = _seedRepository.GetInsertScript(new SeedRow(availableSeed.SeederAttribute.SeedName, "1.0"));

            ExecuteQuery(insertScript);
        }
Esempio n. 3
0
        /// <summary>
        /// Runs the seed.
        /// </summary>
        /// <param name="availableSeed">The available seed.</param>
        protected virtual void RunSeed(SeedInfo availableSeed)
        {
            var concreteClass = Activator.CreateInstance(availableSeed.ConcreteType, _currentDbContext.Context, _logger, SeedConfiguration) as SeedBase;

            concreteClass.SeedData();
        }