1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public static void TestLoadPersonnes()
{
TimeSpan delaiEF;
TimeSpan delaiNpgsql;
Stopwatch swEF = new Stopwatch();
Stopwatch swNpgsql = new Stopwatch();
try
{
swEF.Start();
using (var context = new AdoModelContainer())
{
var result = context.personnes.ToList();
}
swEF.Stop();
swNpgsql.Start();
using (var con = new NpgsqlConnection(cs))
{
con.Open();
//SQL générée par context.personnes.ToString() :
//SELECT "Extent1"."id_personne", "Extent1"."nom", "Extent1"."prenom", "Extent1"."nom_contact", "Extent1"."prenom_contact", "Extent1"."no_civique", "Extent1"."rue", "Extent1"."ville", "Extent1"."cp", "Extent1"."tel_res", "Extent1"."tel_trav", "Extent1"."poste_trav", "Extent1"."cell", "Extent1"."courriel", "Extent1"."actif", "Extent1"."date_maj", "Extent1"."province", "Extent1"."pays", "Extent1"."id_vision" FROM "personnes" AS "Extent1"
string sql = "SELECT Extent1.id_personne, Extent1.nom, Extent1.prenom, Extent1.nom_contact, Extent1.prenom_contact, Extent1.no_civique, Extent1.rue, Extent1.ville, Extent1.cp, Extent1.tel_res, Extent1.tel_trav, Extent1.poste_trav, Extent1.cell, Extent1.courriel, Extent1.actif, Extent1.date_maj, Extent1.province, Extent1.pays, Extent1.id_vision FROM personnes AS Extent1";
List<personnes> testLst = new List<personnes>();
using (var cmd = new NpgsqlCommand(sql, con))
{
using (NpgsqlDataReader rdr = cmd.ExecuteReader())
while (rdr.Read())
{
personnes pers = new personnes();
pers.id_personne = (int)rdr["id_personne"];
pers.nom = (string)rdr["nom"];
pers.prenom = (rdr["prenom"] is DBNull) ? null : (string)rdr["prenom"];
pers.nom_contact = (rdr["nom_contact"] is DBNull) ? null : (string)rdr["nom_contact"];
pers.prenom_contact = (rdr["prenom_contact"] is DBNull) ? null : (string)rdr["prenom_contact"];
pers.no_civique = (rdr["no_civique"] is DBNull) ? null : (string)rdr["no_civique"];
pers.rue = (rdr["rue"] is DBNull) ? null : (string)rdr["rue"];
pers.ville = (rdr["ville"] is DBNull) ? null : (string)rdr["ville"];
pers.cp = (rdr["cp"] is DBNull) ? null : (string)rdr["cp"];
pers.tel_res = (rdr["tel_res"] is DBNull) ? null : (string)rdr["tel_res"];
pers.tel_trav = (rdr["tel_trav"] is DBNull) ? null : (string)rdr["tel_trav"];
pers.poste_trav = (rdr["poste_trav"] is DBNull) ? null : (string)rdr["poste_trav"];
pers.cell = (rdr["cell"] is DBNull) ? null : (string)rdr["cell"];
pers.courriel = (rdr["courriel"] is DBNull) ? null : (string)rdr["courriel"];
pers.actif = (rdr["actif"] is DBNull) ? null : (bool?)rdr["actif"];
pers.date_maj = (rdr["date_maj"] is DBNull) ? null : (DateTime?)rdr["date_maj"];
pers.province = (rdr["province"] is DBNull) ? null : (string)rdr["province"];
pers.pays = (rdr["pays"] is DBNull) ? null : (string)rdr["pays"];
pers.id_vision = (rdr["id_vision"] is DBNull) ? null : (int?)rdr["id_vision"];
testLst.Add(pers);
}
}
}
swNpgsql.Stop();
delaiEF = swEF.Elapsed;
delaiNpgsql = swNpgsql.Elapsed;
}
catch (Exception ex) { MessageBox.Show("erreur : " + ex.Message, "erreur", MessageBoxButton.OK, MessageBoxImage.Error); }
} |
Partager