Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用LINQ查询包含多个子表?_C#_Linq - Fatal编程技术网

C# 如何使用LINQ查询包含多个子表?

C# 如何使用LINQ查询包含多个子表?,c#,linq,C#,Linq,我有这门课: public class Word { public string WordId { get; set; } // WordId (Primary key) (length: 20) public int WordIdentity { get; set; } // WordIdentity public virtual System.Collections.Generic.ICollection<WordForm> WordForms { get

我有这门课:

public class Word
{
    public string WordId { get; set; } // WordId (Primary key) (length: 20)
    public int WordIdentity { get; set; } // WordIdentity
    public virtual System.Collections.Generic.ICollection<WordForm> WordForms { get; set; } // WordForm.FK_WordFormWord
    public Word()
    {
        WordForms = new System.Collections.Generic.List<WordForm>();
    }
}
我正在尝试检索word、wordForm、Samplementes和WordDefinitions的数据,但我不确定如何对select进行编码。以下是我目前掌握的情况:

var words = db.Words
            .Include(w => w.WordForms)
            // How do I include SampleSentences
            // and WordDefinitions ?
            .AsNoTracking()
            .ToListAsync();
有人能告诉我怎样才能包含示例和单词定义吗?我尝试执行此操作,但语法检查失败:

 .Include(w => w.WordForms.SampleSentences)

只需在“包含”中使用“选择”:

 .Include(w => w.WordForms.Select(f => f.SampleSentences))
 .Include(w => w.WordForms.Select(f => f.WordDefinitions))

非常感谢。如果我这样做了,那么我还需要平原:。包括(w=>w.WordForms)以及?@SamanthaJ否,因为任何包括的路径都已经包括所有子路径。
 .Include(w => w.WordForms.SampleSentences)
 .Include(w => w.WordForms.Select(f => f.SampleSentences))
 .Include(w => w.WordForms.Select(f => f.WordDefinitions))