The linq query which returns 'g' (thus the grouping result) returns the result of a merge of two queries, the grouped data (the keys) and the entities related to the grouped keys. So indeed, 'g' is an enumerable over entities, but to get that, the runtime fetches two queries and merges them (as it's a hierarchical set).
The excluded fields are specified with an extension method which expects the fields to be excluded to be part of the TSource type of the query. Your IQueryable<TSource> has as TSource an IGrouping<T, U>, where U is the entity type and T is the keytype. So this clashes. This is caused by the fact that IGrouping is a hierarchical set, not a flat enumerable: per key you have an enumerable, not just 1 enumerable.
That's why you can't specify the excludingfields on these queries, even though it might be ok to do so in theory. There's no code in the runtime at this point to support this.
I just tried to add an extension method which uses an IGrouping<T, U> but that failed deep inside the core where it couldn't create a correlation filter between key query and entity query. Avoiding to waste time on figuring out why that was, I tried the obvious:
you can add the excluding fields call to the original source
->
[Test]
public void GetAllEmployeesWithoutPhotoNorNoteFields2()
{
using(DataAccessAdapter adapter = new DataAccessAdapter())
{
LinqMetaData metaData = new LinqMetaData(adapter);
var q = (from e in metaData.Employee.ExcludeFields(x => x.Photo, x => x.Notes)
group e by e.ReportsTo into g
select g);
int count = 0;
foreach(var g in q)
{
count++;
foreach(var v in g)
{
Assert.IsTrue(v.Photo.Length <= 0);
Assert.IsTrue(v.Notes.Length <= 0);
}
}
Assert.AreEqual(6, count);
}
}
here I group on reports to and exclude photo and notes from the entities.