为什么首先从Entity Framework中的外键列获取数据?

时间:2016-09-04 10:41:04

标签: c# entity-framework ef-code-first

这是我的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数据

0 个答案:

没有答案