我有一个简单的服务表结构,每个服务都有很多设施.在数据库中,这是一个Service表和一个Facility表,其中Facility表具有对Service表中的行的引用.
在我们的应用程序中,我们有以下LINQ工作:
Services
.Where(s => s.Facilities.Any(f => f.Name == "Sample"))
.GroupBy(s => s.Type)
.Select(g => new { Type = g.Key, Count = g.Count() })
Run Code Online (Sandbox Code Playgroud)
但由于我无法控制的原因,源集在Where调用之前被投射到非实体对象,这样:
Services
.Select(s => new { Id = s.Id, Type = s.Type, Facilities = s.Facilities })
.Where(s => s.Facilities.Any(f => f.Name == "Sample"))
.GroupBy(s => s.Type)
.Select(g => new { Type = g.Key, Count = g.Count() })
Run Code Online (Sandbox Code Playgroud)
但这引发了以下异常,没有内部异常:
EntityCommandCompilationException: The nested query is not supported. Operation1='GroupBy' Operation2='MultiStreamNest'
Where …