daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public Class Comment
  2.     {
  3.         public int CommentID { get; set; }
  4.         public string CommentContent { get; set; }
  5.         public virtual User User { get; set; }
  6.         public virtual DateTime CommentCreationTime { get; set; }
  7.     }
  8.  
  9. public class User
  10. {      
  11.  
  12.     public int UserID { get; set; }
  13.     public string UserName { get; set; }
  14.     public string UserPassword { get; set; }
  15.  
  16.     public string UserImageUrl{get; set;}
  17.     public DateTime UserCreationDate { get; set; }
  18.  
  19.     public virtual List<Comment> Comments { get; set; }
  20. }
  21.  
  22.   public void AddComment()
  23.   {
  24.         User user = new User() { UserID = 1 };            
  25.         Comment comment = new Comment() { CommentContent = "This is a comment", CommentCreationTime = DateTime.Now, User = user };
  26.  
  27.         var ctx = new WallContext();
  28.         comments = new CommentsRepository(ctx);
  29.  
  30.         comments.AddComment(comment);
  31.         ctx.SaveChanges();
  32.    }
  33.    
  34. public void AddComment()
  35.   {
  36.        var ctx = new WallContext();
  37.  
  38.         User user = new User() { UserID = 1 };  
  39.  
  40.         ctx.Users.Attach(user);
  41.  
  42.         Comment comment = new Comment() { CommentContent = "This is a comment", CommentCreationTime = DateTime.Now, User = user };
  43.  
  44.         comments = new CommentsRepository(ctx);
  45.  
  46.         comments.AddComment(comment);
  47.         ctx.SaveChanges();
  48.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top