c# - An object is not in a list after being added to a list -
I am developing an MVC 4 internet application in C # and having trouble adding one object to a list .
This is my book class:
public class book {public book () {comments = new collection & lt; Comment & gt; (); } [Key] Public ID {Receive; Set; } Public string title {get; Set; } Public String Writer {get; Set; } Public String Username {get; Set; } Public identification & lt; Comment & gt; Comments {get; Set; }}
Here is my comment class:
public class comment {[key] public ID (get); Set; } Receive public string comment text { Set; } Public String Username {get; Set; }}
Here's my method:
This is my indexing method:
Public Function Index (int id) {var commentsBookViewModel = new commentsViewModel (); CommentsBookViewModel.bookId = ID; CommentsbookviewModel.IsUser LogDidin = us.IsUserLoggedIn (); CommentsBookViewModel.loggedInUserName = us.GetCurrentlyLoggedInUserName (); Comments BookViewModel.comments = db.books.Where (b = & gt; bid == ID). First and last default (). notes. ToList (); See Return (commentsBookViewModel); }
The comment has been added to the book's comment list after the method, and the index method is called, there is no comment in the list of comments books.
Can I help?
Thanks in advance
Comments
Post a Comment