private static void Seed(ForumDbContext context) { var users = new[] { new User("Gosho", "123"), new User("Pesho", "123"), new User("Ivan", "123"), new User("Merry", "123"), }; context.Users.AddRange(users); var categories = new[] { new Category("C#"), new Category("Support"), new Category("Python"), new Category("EF KOP") }; var post = new[] { new Post("C# Rulz", "Верно", categories[0], users[0]), new Post("Python Rulz", "пак верно", categories[2], users[1]), new Post("My computer is shiT", "Верно", categories[1], users[2]), }; context.Posts.AddRange(post); var replies = new[] { new Reply("Turn it on", post[2], users[0]), new Reply("Yep", post[0], users[3]), }; context.AddRange(replies); context.SaveChanges(); }
private static void Seed(ForumDbContext context) { var users = new[] //Users NI E MASIV OT Useri { //Dobavqme si userite izpolzvaiki dvoiniq konstruktor new User("Nasko", 111), new User("Asi", 222), new User("Toni", 333), new User("Toshko", 444), }; //Sega trqbva da gi insertnem v bazata : context.AddRange(users); //Sled Userite dobavqme i Nqkakvi kategorii: var categories = new[] { //Polzvame edinichniq konstruktor new Category("C#"), new Category("Support"), new Category("SQL"), new Category("Front-End") }; var posts = new[] { //Polzvame napraveniq konstruktor new Post("C# Rules", "Vqrno", categories[0], users[0]), new Post("Support Rules", "Pak Vqrno", categories[1], users[1]), new Post("SQL Rules", "Mnogo Vqrno", categories[2], users[2]), new Post("Front-End Rules", "Oshte po Vqrno", categories[3], users[3]), }; context.Posts.AddRange(posts); //Pravim si i Nqkolko Replies n Postovete. var replies = new[] { //Polzvame napraveniq konstruktor new Reply("Not the best!", posts[0], users[0]), new Reply("Not goot at all", posts[1], users[1]), new Reply("Very good", posts[2], users[2]) }; context.Relies.AddRange(replies); /* * //Slagame si danni i v Tags * var tags = new[] * { * new Tag {Name = "Tag C#"}, * new Tag {Name = "Tag Praise"}, * new Tag {Name = "Tag Programming"}, * new Tag {Name = "Tag Microsoft"}, * }; * context.Tags.AddRange(tags); * * //Slagame si danni i v PostTags * var postTags = new[] * { * new PostTags {PostId = 1, TagId = 2}, * new PostTags {PostId = 2, TagId = 2}, * new PostTags {PostId = 1, TagId = 1}, * }; * context.PostTags.AddRange(postTags); */ //NAKRAQ VECHE SLED VSICHKO PISHEM SaveChanges(); context.SaveChanges(); /* * NESHTO NAKRAQ GO SCHUPIH !!! */ }