Skip to content

Instantly share code, notes, and snippets.

@vmussak
Last active July 24, 2018 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmussak/0d2417a578d55583157d957abd9ff7b3 to your computer and use it in GitHub Desktop.
Save vmussak/0d2417a578d55583157d957abd9ff7b3 to your computer and use it in GitHub Desktop.
public IEnumerable<Cliente> BuscarClientes2()
{
var query = "SELECT TOP 100000 * FROM Cliente";
var lstCliente = new List<Cliente>(100000);
_connection.Open();
var cmd = new SqlCommand(query, _connection);
using (var reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
int id = reader.GetOrdinal("Id"),
nome = reader.GetOrdinal("Nome"),
dataNascimento = reader.GetOrdinal("DataNascimento"),
clienteEspecial = reader.GetOrdinal("ClienteEspecial"),
nomeDaMae = reader.GetOrdinal("NomeDaMae"),
quantidadeFilhos = reader.GetOrdinal("QuantidadeFilhos");
while (reader.Read())
lstCliente.Add(new Cliente
{
Id = reader.GetInt32(id),
Nome = reader.GetString(nome),
DataNascimento = reader.GetDateTime(dataNascimento),
ClienteEspecial = reader.GetBoolean(clienteEspecial),
NomeDaMae = reader.GetString(nomeDaMae),
QuantidadeFilhos = reader.GetByte(quantidadeFilhos)
});
}
}
return lstCliente;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment