使用 thenInclude throws System.InvalidOperationException 链接多个包含

Chaining multiple include with thenInclude throws System.InvalidOperationException

考虑这个简化模型:

public class Field 
{
   public string Name { get; set; }
   public MultilingualString Label { get; set; }
   public MultilingualString Placeholder { get; set; }
}

public class MultilingualString 
{
   public string DefaultText { get; set; }
   public IList<Globalization> Globalizations { get; set; }
}

public class Globalization 
{
   public string Text { get; set; }
   public Language Language { get; set; }
}

public class Language
{
   public string Name { get; set; }
   public string CultureString { get; set; }
}

使用我的上下文,我试图通过使用以下命令获取我的所有字段并包括它们的标签和占位符以及全球化和语言(整个事情):

var field = context.Fields
   .Include(x => x.Label.Globalizations)
   .ThenInclude(x => x.Language)
   .Include(x => x.Placeholder.Globalizations)
   .ThenInclude(x => x.Language)
   .ToList();

我抛出以下异常:

System.InvalidOperationException Invalid attempt to read when no data is present.

但是,仅使用第一个 include/theninclude,我确实得到了预期的结果。

什么给了?这是一个已知错误,还是我误解了 Include/ThenInclude 语法?

这是使用带有 VS2015 RC 的 ef7 beta4

这是 EF 7 中的错误。应该用 aspnet/EntityFramework#2474, which will not be in the public EF build until beta 6. Of course, you can also try nightly builds

修复