public static Planete PlaneteEntiteToPlaneteModele(PlaneteEntite planete) { return(new Planete { Nom = planete.Nom, Volume = planete.Volume, Masse = planete.Masse, Anneaux = planete.Anneaux, AnnéeDecouverte = planete.AnnéeDecouverte, NbreSatellite = planete.NbreSatellite, PeriodeRevo = planete.PeriodeRevo, PlanIm = planete.PlanIm }); }
public static List <PlaneteEntite> GetAllPlanete() { string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\UniversDATABase.mdf;Integrated Security=True"; string executable = System.Reflection.Assembly.GetExecutingAssembly().Location; string path = (System.IO.Path.GetDirectoryName(executable)); AppDomain.CurrentDomain.SetData("DataDirectory", path); List <PlaneteEntite> listOfPlanete = new List <PlaneteEntite>(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string sql = "SELECT * FROM [UniversDATABase].[Planete]"; using (var command = new SqlCommand(sql, connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var planeteE = new PlaneteEntite(); planeteE.Nom = reader["PlaneteNom"].ToString(); planeteE.Volume = reader["PlaneteVolume"].ToString(); planeteE.Masse = reader["PlaneteMasse"].ToString(); planeteE.Anneaux = reader["PlaneteAnneaux"].ToString(); planeteE.AnnéeDecouverte = reader["PlaneteDecouverte"].ToString(); planeteE.NbreSatellite = reader["PlaneteNBSat"].ToString(); planeteE.PeriodeRevo = reader["PlanetePeriodeRevo"].ToString(); planeteE.PlanIm = reader["PlanetePathIm"].ToString(); listOfPlanete.Add(planeteE); } } } connection.Close(); return(listOfPlanete); } }