I have two tables, one for patients and one for queries. In summary, the tables have the following structure:
Patients
int id;
string nome;
string cartaoSus;
Queries
int id;
int idPaciente;
dateTime data;
When I want a patient report with scheduled appointments, I do so:
//Crio uma classe que engloba as duas tabelas:
private class consultaCompleta
{
int idConsulta;
int idPaciente;
dateTime data;
string nome;
string cartaoSus;
}
//Crio as listas referentes à cada uma das tabelas:
private void montaConsulta(int idConsulta)
{
List<pacientes> listaPaciente = model.pacientes.ToList(); //pego tudo da tabela
List<consultas> listaConsulta = model.consultas.ToList(); //pego tudo da tabela
List<consultaCompleta> listaConsultaCompleta = (from c in listaConsulta
join p in listaPaciente on c.idPaciente equals p.id
select new consultaCompleta()
{
idConsulta = c.id,
idPaciente = p.id,
data = c.data,
nome = p.nome,
cartaoSus = p.cartaoSus
})
.Where(p => p.id.Equals(idConsulta))
.ToList();
}
The biggest question is this: I always get all the data from the tables and join later. Is there another way to do this by grabbing the table first (how did bigown
respond to me)? How to do it then?
I'm sorry to have practically redone the whole question, but I need to know this issue of slow queries, as my bank will look great in the future.