score:2

although ef core 2.1 introduced improvements to linq groupby translation, the implementation is still far from perfect and produces exceptions in many scenarios due to invalid sql generation. your scenario is just one of them and is not working even with the recent at this time ef core 2.1.1 bits.

the first thing you should do is to submit it to the ef core issue tracker, so they know and fix it when possible.

the problem seems to be related to the key property aliasing (it also doesn't work if you use the "normal" .groupby(e => e.typeid).orderby(g => g.key)). the current workaround i've found is to use anonymous type key having the same property name(s) as the source(s):

_context.mytable
    .groupby(e => new { e.typeid })
    .orderby(g => g.key.typeid)
    .select(g => g.count()) 

More Query from same tag