I have a simple tabular structure of services with each number of objects. In the database, this is the Service table and Facility table, where the Facility table has a link to a row in the service table.
In our application, we have the following LINQ operation:
Services .Where(s => s.Facilities.Any(f => f.Name == "Sample")) .GroupBy(s => s.Type) .Select(g => new { Type = g.Key, Count = g.Count() })
But for reasons beyond my control, the source set is projected onto an object without an entity before calling Where as follows:
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() })
But this raises the following exception without an internal exception:
EntityCommandCompilationException: The nested query is not supported. Operation1='GroupBy' Operation2='MultiStreamNest'
Removing Where , however, makes it work, which only makes me believe in this particular combination of method calls:
Services .Select(s => new { Id = s.Id, Type = s.Type, Facilities = s.Facilities })
Is there a way to do the above work: select a non-entity object, and then use Where and GroupBy as a result of the request? Adding ToList after Select works, but a large set of sources makes this impossible (it will query the database and then group the logic in C #).
c # linq linq-to-entities entity-framework
Steve Klรถsters Nov 26 '14 at 15:10 2014-11-26 15:10
source share