Пример #1
0
        private static void AddRatings(RatingContext context)
        {
            var ratings = Enumerable.Range(0, 100).Select(bookId => new BookRating {
                BookId = bookId, Rating = random.Next(0, 11)
            });

            context.BookRatings.AddRange(ratings);
            context.SaveChanges();
        }
Пример #2
0
        public static void Initialize(RatingContext context, bool resetDb)
        {
            if (resetDb)
            {
                context.Database.EnsureDeleted();
            }

            context.Database.Migrate();

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

            AddRatings(context);
        }