Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Class Comment
- {
- public int CommentID { get; set; }
- public string CommentContent { get; set; }
- public virtual User User { get; set; }
- public virtual DateTime CommentCreationTime { get; set; }
- }
- public class User
- {
- public int UserID { get; set; }
- public string UserName { get; set; }
- public string UserPassword { get; set; }
- public string UserImageUrl{get; set;}
- public DateTime UserCreationDate { get; set; }
- public virtual List<Comment> Comments { get; set; }
- }
- public void AddComment()
- {
- User user = new User() { UserID = 1 };
- Comment comment = new Comment() { CommentContent = "This is a comment", CommentCreationTime = DateTime.Now, User = user };
- var ctx = new WallContext();
- comments = new CommentsRepository(ctx);
- comments.AddComment(comment);
- ctx.SaveChanges();
- }
- public void AddComment()
- {
- var ctx = new WallContext();
- User user = new User() { UserID = 1 };
- ctx.Users.Attach(user);
- Comment comment = new Comment() { CommentContent = "This is a comment", CommentCreationTime = DateTime.Now, User = user };
- comments = new CommentsRepository(ctx);
- comments.AddComment(comment);
- ctx.SaveChanges();
- }
Add Comment
Please, Sign In to add comment