I have 2 tables in a SqlServer database. One call to another and another. I'm trying to return all states of the tbState table that have at least one city (tbCity) and with the properties tbCity.bnlActivityCity and tbCity.blnExibirNoPortal = true. The result should be sorted alphabetically by state name.
I'm trying like this:
IQueryable<tbEstado> ListaDeEstados = ctx.tbEstado
.Join(ctx.tbCidade, estado => estado.idEstado, cidade => cidade.idEstado, (estado, cidade) => new { estado, cidade })
.Where(e => e.cidade.bnlAtivarCidade == true && e.cidade.blnExibirnoPortal == true)
.Select(e => e.estado)
.GroupBy(e => e.idEstado)
.Select(group => group.First()).OrderBy(e => e.txtNomeEstado);
But I'm getting the following error:
Additional information: The 'First' method can only be used as a final query operation. Consider using the method 'FirstOrDefault' in this instance instead.
Could someone help?