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))