Exemple #1
0
 private static void DeletePostFromDB(BlogDBContext db)
 {
     var post = db.Posts.FirstOrDefault(p => p.Comments.Count > 0);
     var comment = post.Comments.FirstOrDefault();
     comment.Users.Comments.Remove(comment);
     post.Comments.Remove(comment);
     db.SaveChanges();
 }
Exemple #2
0
 private static void AddPostToDB(BlogDBContext db)
 {
     Posts post = new Posts()
     {
         AuthorId = 2,
         Title = "title",
         Body = "body",
         Date = DateTime.Now
     };
     db.Posts.Add(post);
     db.Users.Find(2).Posts.Add(post);
     db.SaveChanges();
 }
Exemple #3
0
 private static void UpdateDataFromDB(BlogDBContext db)
 {
     var user = db.Users.Find(2);
     user.FullName = "updated";
     db.SaveChanges();
 }