The correct way is:
invoices = invoices.OrderBy(m => m.Datum).ThenBy(m => m.Rechnungsnummer).ToListAsync();
if (invoices != null && invoices.Count() >= 1)
{
qry_order = invoices.FirstOrDefault().orderId;
}
We need to check count is greater than or equal to 1.