نوشته شده توسط
sarah2
سلام
چطور میشه نظرات تو در تو ایجاد کرد؟ با یک سطح تو در تو
لطفا از پایه توضیح بدید
ایا کلاس زیر درسته؟
public class Comments
{
public int CommentID { get; set; }
public string Name { get; set; }
public string Text { get; set; }
public Nullable<int> ParentID { get; set; }
}
اگر از EF استفاده میکنید باید یگ Navigation Property به کلاس Comments داشته باشین. الان فقط همین رو کم دارین.
همچنین باید یک خصوصیت بصورت لیست برای دسترسی به پاسخها داشته باشین.
نمونه:
public class Comment
{
public Comment()
{
Scores = new HashSet<Score>();
Replies = new HashSet<Comment>();
}
public int CommentId { get; set; }
public string Body { get; set; }
public int PostId { get; set; }
public bool Approved { get; set; }
public int? ParentCommentId { get; set; }
public virtual Post Post { get; set; }
[ForeignKey("ParentCommentId")]
public virtual Comment ParentComment { get; set; }
public virtual ICollection<Comment> Replies { get; set; }
public virtual ICollection<Score> Scores { get; set; }
}