public List <EntityHarley> GetAllHarleys() { using (GarageContext context = new GarageContext()) { return(context.Harleys.ToList()); } }
//methode delete public void Delete(EntityHarley Harley) { using (GarageContext context = new GarageContext()) try { context.Harleys.Attach(Harley); context.Harleys.Remove(Harley); context.SaveChanges(); } catch { throw; } }
//méthode create public void Create(EntityHarley Harley) { using (GarageContext context = new GarageContext()) { try { context.Harleys.Add(Harley); context.SaveChanges(); } catch { throw; } } }
//méthode update public void Update(EntityHarley Harley) { using (GarageContext context = new GarageContext()) { try { context.Harleys.Attach(Harley); //On spécifie l'entité modifiée context.Entry <EntityHarley>(Harley).State = EntityState.Modified; } catch { throw; } } }