You should be able to project an anonymous type, and then use ToArray() as soon as you return to Linq to land objects using AsEnumerable() :
var sites = (from country in db.Countries select new { Country = country.Title, Cities = country.Cities.Select(m => m.Title) }) .AsEnumerable() .Select(country => new SitiesViewByUser() { Country = country.Title, City = country.Cities.ToArray() };
The problem is that ToArray() simply not defined for the Linq to Entities IQueryable (what would be the equivalent call in SQL?). Therefore, you have to capture your results, switch to Linq on objects, and then you can materialize them as needed.
Brokenglass
source share