这是我的Comment
课程:
[Table("Comment")]
publicclass Comment
{
public Comment()
{
SubComments = new HashSet<SubComment>();
}
public Guid ID { get; set; }
public string text { get; set; }
public virtual ICollection<SubComment> SubComments { get; set; }
}
这是Subcomment
类:
[Table("SubComment")]
public class SubComment
{
public Guid ID { get; set; }
public Guid Comment_ID { get; set; }
public string text{ get; set; }
public virtual Comment Comment1 { get; set; }
}
这是我上下文中的OnModelCreating
方法:
modelBuilder.Entity<Comment>()
.HasMany(e => e.SubComments)
.WithRequired(e => e.Comment1)
.HasForeignKey(e => e.Comment_ID);
现在举例来说,如果我跑:
var test = DB.Comments.Where(w => w.text == "a");
为什么Comments
数据还会显示subcomments
数据?
我只需要Comments
数据