static void Main() { using (var context = new ForumContext()) { //var questions = context.Questions.Count(); //Console.WriteLine(questions); //var user = new User() //{ // FirstName = "Nick", // LastName = "Genov", // Gender = Gender.Male, // //Username = "******", // RegisteredOn = DateTime.Now //}; //context.Users.Add(user); //context.SaveChanges(); //var question = new Question() //{ // Title = "How do I create a code first project?", // Content = "PLS help.", // AuthorId = 2 //}; //context.Questions.Add(question); //context.SaveChanges(); var question = context.Questions.Find(1); question.Tags.Add(new Tag() { Name = "Random questions" }); question.Tags.Add(new Tag() { Name = "Silly stuff" }); context.SaveChanges(); foreach (var tag in question.Tags) { Console.WriteLine(tag.Name); } Console.WriteLine(question.Content); } }
static void Main() { var context = new ForumContext(); var count = context.Questions.Count(); Console.WriteLine(count); //var question = new Question(); //question.Id = 1; //count.Add(question); //Console.WriteLine(question); }
static void Main() { using (var context = new ForumContext()) { var user = new User() { UserInfo = new UserInfo() { FirstName = "Nick", LastName = "Genov" }, Gender = Gender.Male, Username = "******", RegisteredOn = DateTime.Now }; context.Users.Add(user); context.SaveChanges(); var question = new Question() { Content = "Exam preparation", Title = "C# Exam", AuthorId = 1 }; context.Questions.Add(question); context.SaveChanges(); user = context.Users.Find(2); Console.WriteLine(user.UserInfo.FirstName); question.Tags.Add(new Tag { Name = "Homework" }); question.Tags.Add(new Tag() { Name = "Exam" }); context.SaveChanges(); foreach (var tag in question.Tags) { Console.WriteLine(tag.Name); } } }