2
I have 2 tables in a Sqlserver bank. One tbState call and another tbCity. I am trying to return all states of the table tbState that have at least one city (tbCity) and with the properties tbCity.bnlAtivarCity and tbCity.blnExibirNoPortal = true. The result should be sorted alphabetically by the 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 method 'First' can only be used as a final query Operation. Consider using the method 'Firstordefault' in this instance Instead.
Could someone help?
Have you figured it out yet? I remember going through something like this and doing a gambit. Like
ListaDeEstados
receives the normal list (without ordering) and then you order.. drew??– rLinhares