private static void DeleteCommentData(BlogDbContext db) { var comment = db.Comments.Single(c => c.Id == 1); db.Comments.Remove(comment); db.SaveChanges(); Console.WriteLine($"Comment #{comment.Id} deleted."); }
private static void DeletePostData(BlogDbContext db) { var post = db.Posts.Single(p => p.Id == 31); db.Comments.RemoveRange(post.Comments); post.Tags.Clear(); db.Posts.Remove(post); db.SaveChanges(); Console.WriteLine($"Post #{post.Id} deleted."); }
private static void CreateData(BlogDbContext db) { var post = new Post() { AuthorId = 2, Title = "Random Title", Body = "Random Body", Date = DateTime.Now }; db.Posts.Add(post); db.SaveChanges(); Console.WriteLine($"Post #{post.Id} created!"); }
private static void UpdateData(BlogDbContext db) { var user = db.Users.Single(u => u.UserName == "GBotev"); var oldName = user.FullName; user.FullName = "Georgi Botev"; db.SaveChanges(); Console.WriteLine($"User '{oldName}' has been renamed to '{user.FullName}'."); }