Пример #1
0
        public static void Initialize(MailingContext context)
        {
            context.Database.EnsureCreated();

            if (context.Topics.Any())
            {
                return;
            }

            Seed(context);
        }
Пример #2
0
        private static void Seed(MailingContext context)
        {
            var topicsNames = new[] {
                "Sport", "Books", "Electronics", "Toys", "Movies", "Automotive", "Clothing", "Beauty", "Games", "Garden"
            };

            var topics = topicsNames.Select(value => new Topic {
                Name = value
            });

            context.Topics.AddRange(topics);

            context.SaveChanges();
        }