LINQ не переводит FirstOrDefault() на язык SQL. Работает, если там поставить Count()
using (ApplicationContext db = new ApplicationContext())
{
outputForm myForm = new outputForm();
var list = db.Penalties.GroupBy(key => key.IdDriversNavigation.FullName,
record => record.IdTraficCopNavigation.FullName,
(key, record) => new
{
driver = key,
traficCop = record.FirstOrDefault()
});
myForm.myGrid.DataSource = list.ToList();
myForm.Show();
}
************** Текст исключения **************
System.InvalidOperationException: The LINQ expression '(GroupByShaperExpression:
KeySelector: (d.FullName),
ElementSelector:(ProjectionBindingExpression: EmptyProjectionMember)
)
.FirstOrDefault()' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.